<?php
/**
 * ============================================================================
 *  SETTINGS > YOUR PREFERENCES > GENERAL  (settings-profile.php)
 * ----------------------------------------------------------------------------
 *  Tabs: Profile | Email | Calendar | Tasks | Security
 *  Forms marked data-settings-form show the bottom save bar when changed.
 *  Shared:  includes/settings-nav.php (left menu), assets/css/settings.css,
 *           assets/js/settings.js
 *  DUMMY values come from current_user(); wire Save to your DB later.
 * ============================================================================
 */
require_once __DIR__ . '/includes/config.php';
require_once __DIR__ . '/includes/settings-ui.php';
require_login();

$user  = current_user();
$parts = explode(' ', $user['name'], 2);
$first = $parts[0];
$last  = isset($parts[1]) ? $parts[1] : '';

if (!function_exists('info_label')) {
  function info_label($for, $text, $tip) {
    return '<label class="field__label set-label" for="' . e($for) . '">' . e($text)
         . ' <span class="set-info" tabindex="0" data-tip-text="' . e($tip) . '" aria-label="' . e($tip) . '">' . icon('info', 'iconSize-14') . '</span></label>';
  }
}

$page_title      = 'General';
$page_css        = array('dropdown', 'custom-select', 'settings', 'settings-pages', 'object-settings', 'settings-calendar-tasks', 'settings-automation-security');
$page_js         = array('settings', 'settings-pages', 'object-settings', 'settings-calendar-tasks', 'settings-automation-security');
$layout          = 'app';
$active_nav      = '';
$settings_active = 'general';

$PROFILE_TABS = array(
  'profile'    => 'Profile',
  'email'      => 'Email',
  'calling'    => 'Calling',
  'calendar'   => 'Calendar',
  'tasks'      => 'Tasks',
  'security'   => 'Security',
  'automation' => 'Automation',
);
include __DIR__ . '/includes/header.php';
?>

<div class="settings">
  <?php include __DIR__ . '/includes/settings-nav.php'; ?>

  <div class="settings__main">
    <header class="set-head">
      <div>
        <h1 class="set-head__title">General</h1>
      </div>
    </header>

    <!-- Navigation Tabs (reusing os-tabs with responsive More overflow) -->
    <div class="os-tabbar crm-mb-4">
      <nav class="os-tabs" aria-label="General settings" data-os-tabs>
        <?php foreach ($PROFILE_TABS as $t => $label) { ?>
          <a class="os-tab<?php echo $t === 'profile' ? ' is-active' : ''; ?>" data-os-tab="<?php echo e($t); ?>" id="<?php echo e($t); ?>-tab" href="#tab-<?php echo e($t); ?>"<?php echo $t === 'profile' ? ' aria-current="page"' : ''; ?>><?php echo e($label); ?></a>
        <?php } ?>
        <div class="os-dd os-tab-more" data-os-dd data-os-more hidden>
          <button type="button" class="os-tab" data-os-dd-toggle aria-haspopup="true" aria-expanded="false">More<?php echo icon('caret-down', 'iconSize-16'); ?></button>
          <div class="os-pop os-pop--menu os-pop--right" data-os-dd-menu hidden role="menu" data-os-more-menu></div>
        </div>
      </nav>
    </div>

    <!-- ========================================================== PROFILE -->
    <section id="tab-profile" role="tabpanel">
      <p class="set-preferences-note">These preferences only apply to you.</p>

      <form data-settings-form novalidate>
        <div class="card set-card">
          <div class="set-card__head">
            <div>
              <h2 class="set-card__title">Global</h2>
              <p class="set-card__sub">This applies across any CRM accounts you have.</p>
            </div>
          </div>

          <div class="photo-row">
            <div class="photo-row__img" id="profile-photo" data-initials="<?php echo e(initials($user['name'])); ?>"><?php echo e(initials($user['name'])); ?></div>
            <div>
              <div class="photo-row__actions">
                <label class="btn-crm btn-crm--outline btn-crm--sm">
                  Upload photo
                  <input type="file" accept="image/*" hidden data-photo-input="#profile-photo">
                </label>
                <button type="button" class="btn-crm btn-crm--ghost btn-crm--sm" data-photo-remove>Remove</button>
              </div>
              <p class="field__help crm-mt-2">JPG, PNG or GIF, up to 2 MB.</p>
            </div>
          </div>

          <div class="set-grid">
            <div class="field">
              <label class="field__label" for="p-first">First name</label>
              <input class="input" id="p-first" name="first_name" value="<?php echo e($first); ?>" required>
              <p class="field__error">Enter your first name</p>
            </div>
            <div class="field">
              <label class="field__label" for="p-last">Last name</label>
              <input class="input" id="p-last" name="last_name" value="<?php echo e($last); ?>">
            </div>
            <div class="field">
              <?php echo info_label('p-lang', 'Language', 'Choose the language used for your interface.'); ?>
              <div class="custom-select-wrapper" data-custom-select data-type="single" data-search="true">
                <select id="p-lang" name="language" hidden>
                  <option value="Deutsch">Deutsch</option>
                  <option value="English" selected>English</option>
                  <option value="Español">Español</option>
                  <option value="Français">Français</option>
                  <option value="Italiano">Italiano</option>
                  <option value="Nederlands">Nederlands</option>
                  <option value="Português">Português</option>
                  <option value="Hindi">Hindi</option>
                  <option value="日本語">日本語</option>
                </select>
              </div>
            </div>
            <div class="field field--full">
              <?php echo info_label('p-format', 'Date, time, and number format', 'How dates, times, and numbers are displayed in your personal view.'); ?>
              <p class="field__help set-format-preview" data-format-preview>Format: October 15, 2026, 10/15/2026, 1:03 AM CDT, and 1,234.56</p>
              <div class="custom-select-wrapper" data-custom-select data-type="single" data-search="true">
                <select id="p-format" name="format" data-format-select hidden>
                  <option value="en-US" data-example="October 15, 2026, 10/15/2026, 1:03 AM CDT, and 1,234.56" selected>United States</option>
                  <option value="en-GB" data-example="15 October 2026, 15/10/2026, 1:03 am BST, and 1,234.56">United Kingdom</option>
                  <option value="en-IN" data-example="15 October 2026, 15/10/2026, 1:03 am IST, and 1,23,456.00">India</option>
                  <option value="de-DE" data-example="15. Oktober 2026, 15.10.2026, 01:03 MESZ und 1.234,56">Germany</option>
                  <option value="fr-FR" data-example="15 octobre 2026, 15/10/2026, 01:03 UTC+2 et 1 234,56">France</option>
                  <option value="ja-JP" data-example="2026年10月15日 10/15/2026 1:03 JST 1,234.56">Japan</option>
                  <option value="en-AU" data-example="15 October 2026, 15/10/2026, 1:03 am AEST, and 1,234.56">Australia</option>
                </select>
              </div>
            </div>
            <div class="field field--full">
              <label class="field__label" for="p-phone">Phone number</label>
              <p class="field__help">We may use this phone number to contact you about security events. Please refer to our privacy policy for <a class="set-link-inline" href="settings-privacy.php" target="_blank">more information <?php echo icon('external', 'iconSize-14'); ?></a></p>
              <div class="phone-input-group">
                <div class="custom-select-wrapper phone-input-group__country" data-custom-select data-type="single" data-search="true">
                  <select name="phone_country" aria-label="Country code" hidden>
                    <option value="US" selected>US</option>
                    <option value="IN">IN</option>
                    <option value="GB">GB</option>
                    <option value="CA">CA</option>
                    <option value="AU">AU</option>
                    <option value="DE">DE</option>
                    <option value="FR">FR</option>
                  </select>
                </div>
                <input class="input phone-input-group__number" id="p-phone" name="phone" type="tel" value="<?php echo e(!empty($user['phone']) ? $user['phone'] : '+1'); ?>" placeholder="+1">
              </div>
            </div>
          </div>
        </div>

        <div class="card set-card">
          <div class="set-card__head">
            <div>
              <h2 class="set-card__title">Defaults</h2>
              <p class="set-card__sub">This only applies to this CRM account.</p>
            </div>
          </div>

          <div class="set-grid">
            <div class="field">
              <?php echo info_label('p-home', 'Default Home Page', 'Choose the home page that appears when you sign in.'); ?>
              <div class="custom-select-wrapper" data-custom-select data-type="single" data-placeholder="Pick a default home page" data-search="true">
                <select id="p-home" name="home_page" hidden>
                  <option value="">Pick a default home page</option>
                  <option value="ads">Ads</option>
                  <option value="buyer-intent">Buyer Intent</option>
                  <option value="calls">Calls</option>
                  <option value="companies">Companies</option>
                  <option value="contacts">Contacts</option>
                  <option value="customer-agent">Customer Agent</option>
                  <option value="dashboards">Dashboards</option>
                </select>
              </div>
            </div>

            <div class="field field--full">
              <div class="set-label">
                <span class="field__label">General working hours</span>
                <span class="set-info" tabindex="0" data-tip-text="Set your standard working schedule and meeting availability." aria-label="Working hours info"><?php echo icon('info', 'iconSize-14'); ?></span>
              </div>
                <a href="user-details.php?tab=preferences&sub=working-hours#working-hours" class="set-link-ext" target="_blank">Edit working hours <?php echo icon('external', 'iconSize-14'); ?></a>
            </div>
          </div>
        </div>
      </form>
    </section>

    <!-- ============================================================ EMAIL -->
    <section id="tab-email" class="crm-d-none" role="tabpanel">
      <p class="set-preferences-note">These preferences only apply to you. For account level email management, go to <a class="link crm-fw-semibold" href="object-settings.php?object=activities">email logging settings</a>.</p>

      <!-- 1. Email (Connect Email) -->
      <div class="card set-card">
        <div class="set-card__head">
          <div>
            <h2 class="set-card__title">Email</h2>
            <p class="set-card__sub">Connect your individual work email accounts to CRM to log, track, send, and receive emails in the CRM CRM.</p>
          </div>
        </div>

        <div class="crm-d-flex crm-flex-column crm-flex-md-row crm-align-items-start crm-justify-content-between crm-gap-4">
          <div class="crm-flex-grow-1">
            <ul class="crm-d-flex crm-flex-column crm-gap-3 crm-mb-4">
              <li class="crm-d-flex crm-align-items-start crm-gap-2 crm-fs-7 crm-text-dark">
                <span class="crm-text-muted crm-flex-shrink-0 crm-d-inline-flex crm-mt-1"><?php echo icon('check', 'iconSize-16'); ?></span>
                <span>Send and schedule emails from CRM</span>
              </li>
              <li class="crm-d-flex crm-align-items-start crm-gap-2 crm-fs-7 crm-text-dark">
                <span class="crm-text-muted crm-flex-shrink-0 crm-d-inline-flex crm-mt-1"><?php echo icon('check', 'iconSize-16'); ?></span>
                <span>Log email replies to CRM automatically</span>
              </li>
              <li class="crm-d-flex crm-align-items-start crm-gap-2 crm-fs-7 crm-text-dark">
                <span class="crm-text-muted crm-flex-shrink-0 crm-d-inline-flex crm-mt-1"><?php echo icon('check', 'iconSize-16'); ?></span>
                <div>
                  <span>Suggest follow-up tasks and capture contact details from your email</span>
                  <span class="crm-d-block crm-fs-8 crm-text-muted crm-mt-1">Requires inbox automation</span>
                </div>
              </li>
            </ul>

            <div class="crm-d-flex crm-align-items-center crm-gap-3">
              <button type="button" class="btn-crm btn-crm--outline" data-dialog-open="#email-connect">Connect email account</button>
            </div>

            <div data-email-list class="crm-mt-4">
              <div class="connect-row">
                <span class="connect-row__icon"><?php echo icon('mail'); ?></span>
                <div class="connect-row__body">
                  <p class="crm-fw-semibold"><?php echo e($user['email']); ?></p>
                  <p class="field__help">Connected &middot; inbox automation on</p>
                </div>
                <span class="badge badge--success">Connected</span>
              </div>
            </div>
          </div>

          <!-- <div class="crm-flex-shrink-0 crm-d-none crm-d-xl-flex crm-align-items-center crm-justify-content-center crm-p-2" aria-hidden="true">
            <svg width="170" height="140" viewBox="0 0 170 140" fill="none" xmlns="http://www.w3.org/2000/svg">
              <g transform="translate(10, 5)">
                <path d="M35 65 L85 30 L135 65 L85 100 Z" fill="#E6FFFA" stroke="#2DD4BF" stroke-width="2" stroke-linejoin="round"/>
                <path d="M45 52 L85 24 L125 52 L85 80 Z" fill="#FFFFFF" stroke="#CBD5E1" stroke-width="1.5" stroke-linejoin="round"/>
                <line x1="62" y1="48" x2="108" y2="48" stroke="#E2E8F0" stroke-width="2" stroke-linecap="round"/>
                <line x1="68" y1="55" x2="102" y2="55" stroke="#E2E8F0" stroke-width="2" stroke-linecap="round"/>
                <path d="M35 65 L85 100 L85 110 L35 75 Z" fill="#CCFBF1" stroke="#2DD4BF" stroke-width="2" stroke-linejoin="round"/>
                <path d="M135 65 L85 100 L85 110 L135 75 Z" fill="#99F6E4" stroke="#2DD4BF" stroke-width="2" stroke-linejoin="round"/>
                <path d="M35 65 L85 100 L135 65 L85 86 Z" fill="#F0FDFA" opacity="0.6"/>
                <circle cx="102" cy="22" r="15" fill="#10B981"/>
                <path d="M96 22 L100 26 L108 18" stroke="#FFFFFF" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>
                <path d="M125 15 L127 10 L129 15 L134 17 L129 19 L127 24 L125 19 L120 17 Z" fill="#F59E0B" opacity="0.8"/>
                <circle cx="75" cy="14" r="2" fill="#3B82F6" opacity="0.7"/>
                <circle cx="138" cy="42" r="1.5" fill="#10B981" opacity="0.7"/>
              </g>
            </svg>
          </div> -->
        </div>
      </div>

      <!-- 2. Configure -->
      <form data-settings-form novalidate>
      <div class="card set-card">
        <h2 class="set-card__title crm-mb-4">Configure</h2>

        <div class="crm-d-flex crm-flex-column crm-gap-4">
          <div class="crm-d-flex crm-flex-column crm-gap-1">
            <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
              <a href="#email-alias" class="link" data-dialog-open="#alias-dialog">Add email alias</a>
            </h3>
            <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base">An email alias allows emails sent outside of CRM to be associated with your user. <a href="#" target="_blank" class="link">Learn more.</a></p>

            <div id="email-alias-section" class="crm-mt-3">
              <p class="crm-fs-8 crm-fw-bold crm-text-dark crm-m-0 crm-mb-2">CURRENT EMAIL ALIASES:</p>
              <div id="email-alias-list" class="crm-d-flex crm-flex-column crm-gap-2">
                <div class="crm-d-flex crm-align-items-center crm-gap-2" data-alias-item="test@gmail.com">
                  <span class="crm-fs-7 crm-text-dark">test@gmail.com</span>
                  <button type="button" class="icon-btn w-32 h-32 crm-rounded-circle" data-remove-alias="test@gmail.com" aria-label="Delete alias test@gmail.com">
                    <?php echo icon('trash', 'iconSize-16'); ?>
                  </button>
                </div>
              </div>
            </div>
          </div>

          <div class="crm-d-flex crm-flex-column crm-gap-1">
            <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
              <a href="#email-signature" class="link" data-dialog-open="#sig-dialog">Manage email signatures</a>
            </h3>
            <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base">Your signature will be used in one-on-one emails through the CRM and as a personalization token for marketing emails.</p>
          </div>

          <div class="crm-d-flex crm-flex-column crm-gap-1">
            <div class="crm-d-flex crm-align-items-center crm-gap-2">
              <label class="check">
                <input type="checkbox" name="include_unsubscribe" id="chk-unsubscribe">
                <span class="check__box" aria-hidden="true"></span>
                <span class="crm-text-dark crm-fw-medium">Include unsubscribe link</span>
              </label>
              <span class="badge crm-bg-indigo-subtle crm-text-indigo">Recommended</span>
            </div>
            <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base crm-ps-4">Include a link at the bottom of your emails allowing recipients to unsubscribe. It will help you stay compliant with local spam laws and improve deliverability.</p>
            <div class="crm-ps-4 crm-mt-2">
              <button type="button" class="btn-crm btn-crm--outline btn-crm--sm" id="btn-unsubscribe-edit" disabled data-dialog-open="#unsub-dialog">Edit unsubscribe link</button>
            </div>
          </div>
        </div>
      </div>
      </form>

      <!-- 3. Never Log -->
      <div class="card set-card">
        <h2 class="set-card__title">Never Log</h2>
        <p class="set-card__sub">The Never Log list ensures emails and meetings with specified domains or email addresses are not automatically logged to your CRM. Admins can manage Never Log for all users in <a href="settings-account-defaults.php" class="link">email logging settings</a>. <a href="help.php#never-log" target="_blank" class="link">Learn more <?php echo icon('external', 'iconSize-14'); ?></a></p>

        <div class="set-toolbar crm-mt-4">
          <?php echo su_search('Search emails or domains', '#never-log-rows'); ?>

          <div class="custom-select-wrapper" data-custom-select data-type="single">
            <select aria-label="View filter" hidden>
              <option value="all" selected>View: All</option>
              <option value="domains">View: Domains</option>
              <option value="emails">View: Emails</option>
            </select>
          </div>

          <div class="custom-select-wrapper" data-custom-select data-type="single">
            <select aria-label="Domains and emails filter" hidden>
              <option value="both" selected>Domains and Emails</option>
              <option value="domains">Domains only</option>
              <option value="emails">Emails only</option>
            </select>
          </div>

          <button type="button" class="btn-crm btn-crm--outline btn-crm--sm crm-ms-auto crm-rounded-md" data-dialog-open="#neverlog-dialog">Add emails or domains</button>
        </div>

        <div class="card set-table-card crm-mt-3">
          <table class="set-table" id="never-log-table">
            <thead>
              <tr>
                <th>Domains and Email Addresses <span class="set-sort-icon">⇅</span></th>
                <th></th>
                <th class="crm-text-end">Blocked for <span class="set-sort-icon">⇅</span></th>
              </tr>
            </thead>
            <tbody id="never-log-rows">
              <tr data-row>
                <td class="crm-fw-semibold" data-name>*@admedia.com</td>
                <td class="crm-text-muted crm-fst-italic crm-fs-7">This item was added by the administrator.</td>
                <td class="crm-text-end"><span class="badge badge--neutral">All Users</span></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>

      <!-- 4. Collapsible Extension Sections -->
      <div class="card set-card crm-p-0 crm-overflow-hidden">
        <details class="set-accordion" open>
          <summary class="set-accordion__summary crm-d-flex crm-align-items-center crm-gap-2 crm-p-3 crm-fs-7 crm-fw-semibold crm-text-dark crm-user-select-none">
            <span class="set-accordion__icon crm-text-muted"><?php echo icon('chevron-down', 'iconSize-16'); ?></span>
            <span>Download the email extension</span>
          </summary>
          <div class="crm-px-4 crm-pb-4">
            <div class="crm-d-flex crm-flex-column crm-gap-4">
              <!-- Gmail Chrome -->
              <div class="crm-d-flex crm-align-items-start crm-gap-3">
                <div class="crm-flex-shrink-0 crm-d-flex crm-align-items-center crm-justify-content-center crm-mt-1">
                  <svg width="24" height="24" viewBox="0 0 24 24"><path fill="#EA4335" d="M12 13.5L2 6V18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6l-10 7.5z"/><path fill="#4285F4" d="M20 4H4c-1.1 0-2 .9-2 2l10 7.5L22 6c0-1.1-.9-2-2-2z"/></svg>
                </div>
                <div class="crm-flex-grow-1">
                  <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                    <a href="https://chrome.google.com/webstore" target="_blank" class="link">Install CRM Sales Extension for Gmail (Chrome)</a>
                  </h3>
                  <p class="crm-m-0 crm-mt-1 crm-fs-7 crm-text-muted crm-lh-base">The Chrome Extension works with Gmail to track email opens, log emails in your CRM automatically, and use templates in your inbox.</p>
                </div>
              </div>

              <!-- Office 365 -->
              <div class="crm-d-flex crm-align-items-start crm-gap-3">
                <div class="crm-flex-shrink-0 crm-d-flex crm-align-items-center crm-justify-content-center crm-mt-1">
                  <svg width="24" height="24" viewBox="0 0 24 24"><rect x="3" y="3" width="8" height="8" fill="#F25022"/><rect x="13" y="3" width="8" height="8" fill="#7FBA00"/><rect x="3" y="13" width="8" height="8" fill="#00A4EF"/><rect x="13" y="13" width="8" height="8" fill="#FFB900"/></svg>
                </div>
                <div class="crm-flex-grow-1">
                  <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                    <a href="https://appsource.microsoft.com" target="_blank" class="link">Download CRM Sales add-in for Office 365</a>
                  </h3>
                  <p class="crm-m-0 crm-mt-1 crm-fs-7 crm-text-muted crm-lh-base">The Office 365 add-in works with Outlook to track email opens, log emails in your CRM automatically, and use templates in your inbox. This is the recommended choice for Office 365 users on all platforms.</p>
                </div>
              </div>

              <!-- Outlook Windows -->
              <div class="crm-d-flex crm-align-items-start crm-gap-3">
                <div class="crm-flex-shrink-0 crm-d-flex crm-align-items-center crm-justify-content-center crm-mt-1">
                  <svg width="24" height="24" viewBox="0 0 24 24"><path fill="#0078D4" d="M2 5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5z"/><path fill="#FFFFFF" d="M12 13L4 7h16l-8 6z"/></svg>
                </div>
                <div class="crm-flex-grow-1">
                  <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                    <a href="#" class="link">Download CRM Sales add-in for Outlook (Windows/PC)</a>
                  </h3>
                  <p class="crm-m-0 crm-mt-1 crm-fs-7 crm-text-muted crm-lh-base">The Outlook for Windows desktop add-in is now in maintenance mode, and we only recommend using this if you do not have an inbox compatible with Office 365. This add-in is able to track email opens, log emails in your CRM, and can use templates. <a href="help.php#outlook-requirements" target="_blank" class="link">System requirements</a></p>
                </div>
              </div>
            </div>
          </div>
        </details>
      </div>

      <div class="card set-card crm-p-0 crm-overflow-hidden">
        <details class="set-accordion" open>
          <summary class="set-accordion__summary crm-d-flex crm-align-items-center crm-gap-2 crm-p-3 crm-fs-7 crm-fw-semibold crm-text-dark crm-user-select-none">
            <span class="set-accordion__icon crm-text-muted"><?php echo icon('chevron-down', 'iconSize-16'); ?></span>
            <span>Extension settings</span>
          </summary>
          <div class="crm-px-4 crm-pb-4">
            <div class="crm-d-flex crm-flex-column crm-gap-4">
              <div class="crm-d-flex crm-flex-column crm-gap-1">
                <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                  <a href="#bcc-addresses" class="link" data-dialog-open="#bcc-dialog">Manage additional BCC addresses</a>
                </h3>
                <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base">Log emails you send to an external CRM in addition to your CRM. Only works for emails sent using a sales extension.</p>
              </div>

              <div class="crm-d-flex crm-flex-column crm-gap-1">
                <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                  <a href="#blocked-ips" class="link" data-dialog-open="#blocked-ips-dialog">Manage blocked IP addresses</a>
                </h3>
                <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base">Don't track email opens or clicks from specific IP addresses. Your current IP address is: <strong>207.244.71.82</strong></p>
              </div>

              <div class="crm-d-flex crm-flex-column crm-gap-1">
                <h3 class="crm-m-0 crm-fs-7 crm-fw-semibold">
                  <a href="settings-sales-extension-views.php" class="link">Customize Sales Extension Views</a>
                </h3>
                <p class="crm-m-0 crm-fs-7 crm-text-muted crm-lh-base">Configure the card layout for each object type and location in your CRM Sales Extension sidebar.</p>
              </div>
            </div>
          </div>
        </details>
      </div>

      <!-- 5. Sales Notifications -->
      <div class="card set-card">
        <h2 class="set-card__title crm-mb-3">Sales Notifications</h2>
        <div class="crm-p-4 crm-rounded-4 crm-bg-warning-subtle crm-border crm-border-warning-subtle crm-fs-7" data-notifications-off>
          <strong class="crm-d-block crm-fw-semibold crm-text-dark crm-mb-1">Notifications are off.</strong>
          <p class="crm-m-0 crm-text-muted crm-fs-7">Give CRM permission to send notifications to this browser.</p>
          <div class="crm-mt-3">
            <button type="button" class="btn-crm btn-crm--primary btn-crm--sm" data-enable-notifications>Turn on</button>
          </div>
        </div>
        <div class="sales-notifications-settings" data-notifications-on hidden>
          <div class="sales-notifications-status">
            <h3>Notifications</h3>
            <p class="sales-notifications-enabled"><span class="sales-notifications-dot" aria-hidden="true"></span>Notifications are on.</p>
            <a class="sales-notifications-manage" href="settings-profile.php#browser-notifications">Manage notifications <span aria-hidden="true">↗</span></a>
          </div>
          <div class="sales-notifications-options" id="browser-notifications">
            <h3>Browser Notifications</h3>
            <p>Choose what you get notified about.</p>
            <label class="check sales-notification-option">
              <input type="checkbox" name="sales_notification_email_opens" checked>
              <span class="check__box" aria-hidden="true"></span>
              <span>Email opens</span>
            </label>
            <label class="check sales-notification-option">
              <input type="checkbox" name="sales_notification_email_clicks" checked>
              <span class="check__box" aria-hidden="true"></span>
              <span>Email clicks</span>
            </label>
            <label class="check sales-notification-option">
              <input type="checkbox" name="sales_notification_document_views" checked>
              <span class="check__box" aria-hidden="true"></span>
              <span>Document views</span>
            </label>
            <label class="check sales-notification-option">
              <input type="checkbox" name="sales_notification_lead_revisits">
              <span class="check__box" aria-hidden="true"></span>
              <span>Lead revisits</span>
            </label>
            <label class="check sales-notification-option is-disabled sales-notification-tooltip" data-tooltip="To enable, you must create at least one saved view." tabindex="0" aria-label="Prospector revisits. To enable, you must create at least one saved view.">
              <input type="checkbox" name="sales_notification_prospector_revisits" disabled>
              <span class="check__box" aria-hidden="true"></span>
              <span>Prospector revisits</span>
            </label>
          </div>
        </div>
      </div>
    </section>

    <!-- ========================================================== CALLING -->
    <section id="tab-calling" class="crm-d-none" role="tabpanel">
  <p class="set-preferences-note">These preferences only apply to you. For account level calling defaults go to <a href="settings-account-defaults.php" class="link">account call settings</a>.</p>

  <form data-settings-form data-calling-settings-form novalidate>
    <h2 class="set-calling-card__title">CRM numbers</h2>
        <p class="set-calling-card__desc crm-mb-4">These are phone numbers that were acquired through CRM and have either been assigned to you, or have assignments that include you. These numbers can be used for both inbound and outbound calling.</p>
  <div class="set-calling-top-actions">
    <button type="button" class="btn-crm btn-crm--outline btn-crm--sm" data-open-audio-messages>Edit audio messages</button>
  </div>

  <div class="card set-card set-calling-card">
    <div class="set-calling-hero">
      <div class="set-calling-card__body">
        <h2 class="set-calling-card__title">Use CRM Calling to streamline your communication and keep all your conversations in one place</h2>
        <p class="set-calling-card__desc">Use a <a href="#" class="link" data-soon="CRM number">CRM number</a>, port an existing number or connect a third-party integration ↗ to start making and receiving calls with automatic call logging.</p>
      </div>
      <div class="set-calling-card__art" aria-hidden="true">
        <img src="assets/img/crm-calling.svg" width="190">
      </div>
    </div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title">Registered numbers</h2>
    <p class="set-calling-section__desc">These are phone numbers you have added that were not acquired through CRM. These lines can only be used to place outbound calls from the CRM and face increased risk of blocked calls and spam labeling from local carriers.</p>
    <button type="button" class="btn-crm btn-crm--outline btn-crm--sm" data-open-phone-modal>Add phone number</button>
    <div class="card set-calling-empty" data-registered-empty>
      <svg width="74" height="62" viewBox="0 0 74 62" fill="none" aria-hidden="true"><path d="M10 49 36 36l28 13-28 13L10 49Z" fill="var(--surface-3)"/><circle cx="36" cy="20" r="12" stroke="var(--border-strong)" stroke-width="2"/><path d="m28 20 5 5 11-12" stroke="var(--border-strong)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="m48 7 3-5m4 10 6-1" stroke="var(--border-strong)" stroke-width="2" stroke-linecap="round"/></svg>
      <p>You do not have any registered phone numbers.</p>
    </div>
    <div class="card set-calling-number-list" data-registered-list hidden></div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title crm-mt-3">Call working hours <span class="set-info" tabindex="0" data-tip-text="Set the hours when you want calls to be routed to you." aria-label="Call working hours info"><?php echo icon('info', 'iconSize-14'); ?></span></h2>
    <p class="set-calling-section__desc">Set the time when you want calls to be routed to you. You can use this to define routing in your phone number setup. This is separate from your general working hours found in <a href="settings-users.php" class="link">Users and Teams</a>.</p>
    <div class="set-calling-hours">
      <div class="set-calling-hours__head"><span>Day</span><span></span><span>Starting time</span><span></span><span>End time</span><span>Timezone</span><span></span></div>
      <div class="set-calling-hours__rows" data-call-hours-rows>
        <div class="set-calling-hours__row" data-call-hours-row>
          <select class="input" aria-label="Day" name="call_day[]"><option value="Mon - Fri">Mon - Fri</option><option value="Sat - Sun">Sat - Sun</option><option value="Every day">Everyday</option><option value="Sun">Sunday</option><option value="Mon">Monday</option><option value="Tue">Tuesday</option><option value="Wed">Wednesday</option><option value="Thu">Thursday</option><option value="Fri">Friday</option><option value="Sat">Saturday</option></select>
          <span class="set-calling-from">from</span>
          <select class="input" aria-label="Starting time" name="call_start[]"><?php for($h=0;$h<24;$h++){foreach([0,30] as $m){$v=sprintf('%02d:%02d',$h,$m);$label=date('g:i A',strtotime($v));echo '<option value="'.e($v).'"'.($v==='09:00'?' selected':'').'>'.e($label).'</option>';}} ?></select>
          <span class="set-calling-to">to</span>
          <select class="input" aria-label="End time" name="call_end[]"><?php for($h=0;$h<24;$h++){foreach([0,30] as $m){$v=sprintf('%02d:%02d',$h,$m);$label=date('g:i A',strtotime($v));echo '<option value="'.e($v).'"'.($v==='17:00'?' selected':'').'>'.e($label).'</option>';}} ?></select>
          <select class="input" aria-label="Timezone" name="call_timezone[]">
            <option>UTC -12:00 Baker Island</option><option>UTC -11:00 Pago Pago</option><option>UTC -10:00 Honolulu</option><option>UTC -09:00 Anchorage</option><option>UTC -08:00 Los Angeles</option><option>UTC -07:00 Denver</option><option>UTC -06:00 Ciudad Juarez</option><option>UTC -06:00 Chihuahua</option><option>UTC -05:00 Cayman</option><option selected>UTC -05:00 Chicago</option><option>UTC -05:00 Coral Harbour</option><option>UTC -04:00 New York</option><option>UTC -03:00 Buenos Aires</option><option>UTC -02:00 South Georgia</option><option>UTC -01:00 Azores</option><option>UTC +00:00 London</option><option>UTC +01:00 Paris</option><option>UTC +02:00 Cairo</option><option>UTC +03:00 Moscow</option><option>UTC +04:00 Dubai</option><option>UTC +05:00 Karachi</option><option>UTC +05:30 New Delhi</option><option>UTC +06:00 Dhaka</option><option>UTC +07:00 Bangkok</option><option>UTC +08:00 Singapore</option><option>UTC +09:00 Tokyo</option><option>UTC +10:00 Sydney</option><option>UTC +12:00 Auckland</option>
          </select>
          <button type="button" class="icon-btn w-32 h-32 crm-rounded-circle" data-remove-call-hours aria-label="Remove working hours"><?php echo icon('trash', 'iconSize-16'); ?></button>
        </div>
      </div>
      <button type="button" class="link set-calling-add-hours" data-add-call-hours>+ Add hours</button>
    </div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title crm-mt-3">Inbound calling preferences</h2>
    <p class="set-calling-section__desc">Set how you want to receive inbound calls to your CRM phone numbers.</p>
    <div class="field set-calling-narrow-field">
      <label class="field__label" for="call-ring-preference">Ring preference</label>
      <select class="input" id="call-ring-preference" name="call_ring_preference"><option>Ring in CRM browser</option><option>Forward to phone number</option><option>Ring in Mobile App</option></select>
    </div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title crm-mt-3">Usage this month</h2>
    <p class="set-calling-section__desc">This is the accumulative overview for all users of calling in your account. You can also view historical minute usage on the <a href="#" class="link" data-soon="Call analytics dashboard">call analytics dashboard <?php echo icon('external', 'iconSize-14'); ?></a>.</p>
    <div class="card set-calling-usage">
      <div class="set-calling-usage__head"><strong>October minute usage&nbsp; <span data-call-usage>0</span> / 12,000</strong><a href="account-billing.php" class="link">Manage minute subscription </a></div>
      <div class="set-calling-progress"><span style="width:0%"></span></div>
      <p>Usage resets at the start of each month. The available minutes are based on your CRM plan and any minute subscriptions in your account.</p>
    </div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title crm-mt-3">Connect an integration</h2>
    <div class="set-calling-integration">
      <div class="set-calling-integration__logo"><svg width="28" height="28" viewBox="0 0 32 32" fill="none" aria-hidden="true"><circle cx="16" cy="16" r="16" fill="#F22F46"/><circle cx="11.5" cy="11.5" r="2.5" fill="#fff"/><circle cx="20.5" cy="11.5" r="2.5" fill="#fff"/><circle cx="11.5" cy="20.5" r="2.5" fill="#fff"/><circle cx="20.5" cy="20.5" r="2.5" fill="#fff"/></svg></div>
      <div class="set-calling-integration__info"><h3 class="set-calling-integration__name"><a href="#connect-twilio" class="link" data-soon="Twilio integration">Sign up or connect your Twilio account</a></h3><p class="set-calling-integration__desc">Get more calling minutes and access additional supported countries</p></div>
    </div>
  </div>

  <div class="set-calling-section">
    <h2 class="set-calling-section__title set-calling-section__title--lg crm-mt-3">Transcription and Analysis</h2>
    <p class="set-calling-section__desc">Conversation Intelligence gives real-time insights into customer conversations and coaching opportunities through call transcription, call analysis and reporting on tracked terms.</p>
    <div class="set-calling-group set-calling-transcription">
      <h3 class="set-calling-group__title">Transcription language</h3>
      <p class="set-calling-group__desc">Choose a preferred language for call transcriptions. Once selected, all calls will be in your preferred language. This choice is separate from your <a href="settings-account-defaults.php" class="link" data-os-tab-jump="profile">language settings</a>.</p>
      <select class="input set-calling-language" name="transcription_language" aria-label="Transcription language"><option value="">Select transcription language</option><option>Chinese</option><option>Danish</option><option>Dutch</option><option>English - Australia</option><option>English - United Kingdom</option><option>English - United States</option><option>English (Welsh)</option><option>Finnish</option><option>French</option><option>German</option><option>Hindi</option><option>Italian</option><option>Japanese</option><option>Portuguese</option><option>Spanish</option></select>
    </div>
    <div class="set-calling-group crm-mt-2">
      <h3 class="set-calling-group__title">Tracked Terms Notifications</h3>
      <p class="set-calling-group__desc">Customize which tracked terms are included in your notifications.</p>
      <div class="set-calling-radios">
        <label class="set-calling-radio"><input type="radio" name="tracked_terms_mode" value="all"><span>All terms</span></label>
        <label class="set-calling-radio"><input type="radio" name="tracked_terms_mode" value="selected" checked><span>Selected Terms</span></label>
      </div>
      <div class="set-calling-terms-box" data-tracked-terms-wrapper>
        <div class="custom-select-wrapper" data-custom-select data-type="single" data-search="true" data-placeholder="Select tracked terms">
          <select id="tracked-terms-select" name="tracked_terms" hidden><option value="" selected>Select tracked terms</option><option value="pricing">Pricing &amp; Discounts</option><option value="competitors">Competitors</option><option value="timeline">Timeline &amp; Next Steps</option><option value="budget">Budget &amp; Authority</option><option value="objections">Common Objections</option></select>
        </div>
      </div>
    </div>
  </div>

  </form>

  <!-- Theme modal: edit audio messages -->
  <dialog class="set-modal set-calling-modal" id="call-audio-dialog" aria-labelledby="call-audio-title">
    <div class="set-modal__head"><h2 class="set-modal__title" id="call-audio-title">Edit audio messages</h2><button type="button" class="icon-btn" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-16'); ?></button></div>
    <div class="set-modal__body">
      <div class="set-calling-modal-tabs" role="tablist"><button type="button" data-audio-tab="add" role="tab" aria-selected="false">Add an audio message</button><button type="button" class="is-active" data-audio-tab="existing" role="tab" aria-selected="true">Edit existing audio messages</button></div>
      <div data-audio-panel="add" hidden>
        <p class="set-calling-modal-intro">Create an audio message or file that can be used across CRM.</p>
        <form data-audio-form>
          <div class="field"><label class="field__label" for="audio-message-name">Message name <span class="crm-text-danger">*</span></label><input class="input" id="audio-message-name" name="message_name" required></div>
          <div class="field"><label class="field__label" for="audio-message-type">Message type <span class="crm-text-danger">*</span></label><select class="input" id="audio-message-type" name="message_type" required><option value="">Choose a message type</option><option disabled>IVR</option><option>Voicemail</option><option disabled>Recording Consent</option><option>Voicemail Drop</option><option disabled>Hold Music</option><option>Hold Message</option><option>Callback Offer</option><option>Callback Greeting</option><option>Callback Confirmation</option></select></div>
          <div class="field"><label class="field__label" for="audio-source">Audio source</label><select class="input" id="audio-source" name="audio_source"><option value="Text-To-Speech">Text-To-Speech</option><option value="Upload Audio">Upload Audio</option></select></div>
          <div class="field" data-audio-text-wrap><label class="field__label" for="audio-message-text">Enter your message</label><p class="field__help">Enter text to create an audio version of your message. The written language must match the selected audio language.</p><textarea class="input" id="audio-message-text" name="message_text" rows="5" maxlength="1000" placeholder="Type your audio message..."></textarea><div class="set-calling-char-count"><span data-audio-count>0</span>/1000</div></div>
          <div class="field set-calling-upload-field" data-audio-file-wrap hidden>
            <label class="field__label" for="audio-file">Upload audio message</label>
            <p class="field__help set-calling-upload-help">Upload an audio file to use as the message.</p>
            <input class="set-calling-file-input" type="file" id="audio-file" name="audio_file" accept=".mp3,.wav,audio/mpeg,audio/wav">
            <label class="set-calling-upload-drop" for="audio-file" tabindex="0" role="button" data-audio-dropzone>
              <svg class="set-calling-upload-icon" viewBox="0 0 40 44" fill="none" aria-hidden="true"><path d="M10 5.5H23L31 13.5V37.5C31 39.2 29.7 40.5 28 40.5H10C8.3 40.5 7 39.2 7 37.5V8.5C7 6.8 8.3 5.5 10 5.5Z" stroke="currentColor" stroke-width="2.5" stroke-linejoin="round"/><path d="M23 5.5V13.5H31M13 22H25M13 28H25M13 34H22" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/><path d="M30 2V13M25 7L30 2L35 7" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
              <span class="set-calling-upload-copy"><strong data-audio-upload-title>Upload a file that is:</strong><span>•&nbsp; An .mp3 or .wav</span><span>•&nbsp; Less than 5MB</span></span>
            </label>
            <p class="set-calling-upload-filename" data-audio-file-name hidden></p>
          </div>
          <div class="set-calling-audio-voice" data-audio-voice-wrap>
            <div class="field"><label class="field__label" for="audio-language">Language</label><select class="input" id="audio-language" name="audio_language"><option>English - United Kingdom</option><option>English - United States</option><option>English (Welsh)</option><option>Finnish - Finland</option><option>French - France</option><option>French - Canada</option><option>German - Germany</option><option>Hindi - India</option><option>Italian - Italy</option><option>Japanese - Japan</option><option>Spanish - Spain</option><option>Chinese</option><option>Danish - Denmark</option><option>Dutch - Netherlands</option><option>English - Australia</option><option>Portuguese - Brazil</option></select></div>
            <div class="field"><label class="field__label" for="audio-voice">Voice</label><div class="set-calling-voice-line"><select class="input" id="audio-voice" name="audio_voice"><option>Kendra</option><option>Kimberly</option><option>Matthew</option><option>Salli</option><option>Joanna-Neural</option><option>Joey-Neural</option><option>Matthew-Neural</option><option>Olivia-Neural</option><option>Brian-Neural</option></select><button type="button" class="icon-btn" data-audio-preview aria-label="Preview voice"><?php echo icon('play', 'iconSize-16'); ?></button></div></div>
          </div>
          <div class="set-calling-audio-legal" data-audio-tts-legal><p class="field__help">You are responsible for ensuring that the audio message does not infringe on intellectual property rights of third parties. If the audio message is for call recording consent, you are responsible for compliance with call recording laws. <a href="#" class="link" data-soon="Call recording laws">Learn more about call recording laws.</a></p></div>
          <div class="set-calling-audio-legal" data-audio-upload-legal hidden><p>You are responsible for ensuring that the audio message does not infringe on the intellectual property rights of third parties. If the audio message is for call recording, you are responsible for compliance with call recording laws. <a href="#" class="link" data-soon="Call recording laws">Learn more about call recording laws</a>.</p><p>CRM reserves the right to review and remove any audio message that violates its <a href="#" class="link" data-soon="Acceptable Use Policy">Acceptable Use Policy</a>.</p></div>
          <div class="set-modal__foot"><button type="button" class="btn-crm btn-crm--ghost" data-dialog-close>Cancel</button><button type="submit" class="btn-crm btn-crm--primary">Save</button></div>
        </form>
      </div>
      <div data-audio-panel="existing">
        <div class="set-calling-existing-search"><label class="set-calling-searchbox"><input class="input" type="search" placeholder="Search messages" data-audio-search aria-label="Search messages"><span aria-hidden="true"><svg viewBox="0 0 20 20" width="17" height="17" fill="none"><circle cx="8.5" cy="8.5" r="5.5" stroke="currentColor" stroke-width="1.4"/><path d="m12.5 12.5 4 4" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg></span></label></div>
        <div class="set-calling-filterbar" role="group" aria-label="Filter audio messages"><button type="button" class="set-calling-filter-trigger" data-audio-filter-toggle="type" aria-expanded="false">Message type <svg class="set-calling-caret-svg" viewBox="0 0 16 16" width="12" height="12" fill="none" aria-hidden="true"><path d="m4 6 4 4 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button><button type="button" class="set-calling-filter-trigger" data-audio-filter-toggle="created" aria-expanded="false">Created by <svg class="set-calling-caret-svg" viewBox="0 0 16 16" width="12" height="12" fill="none" aria-hidden="true"><path d="m4 6 4 4 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button></div>
        <div class="set-calling-existing-table"><table class="set-table"><thead><tr><th class="set-calling-title-col"><button type="button" class="set-calling-sort-trigger" data-audio-sort="name">Message title <span aria-hidden="true">↕</span></button></th><th><span class="set-calling-heading-label">Message type <span class="set-calling-info" title="The type of audio message">ⓘ</span></span><button type="button" class="set-calling-sort-trigger" data-audio-sort="type" aria-label="Sort by message type"><span aria-hidden="true">↕</span></button></th><th><button type="button" class="set-calling-sort-trigger" data-audio-sort="creator">Created by <span aria-hidden="true">↕</span></button></th><th><button type="button" class="set-calling-sort-trigger" data-audio-sort="date">Created date <span aria-hidden="true">↕</span></button></th></tr></thead><tbody data-audio-list><tr data-audio-empty-row><td colspan="4" class="set-calling-existing-empty"><svg class="set-calling-empty-art" viewBox="0 0 190 150" role="img" aria-label="No audio messages"><path d="M20 112 91 73l78 39-77 35-72-35Z" fill="var(--brand-soft)"/><ellipse cx="92" cy="111" rx="29" ry="14" fill="var(--surface)" stroke="var(--border-strong)" stroke-dasharray="3 3"/><path d="M70 100 83 63l18 0 13 37" fill="var(--surface)" stroke="var(--border-strong)" stroke-dasharray="3 3"/><ellipse cx="91" cy="54" rx="31" ry="20" transform="rotate(-12 91 54)" fill="var(--surface)" stroke="var(--border-strong)" stroke-width="4"/><ellipse cx="91" cy="54" rx="23" ry="13" transform="rotate(-12 91 54)" fill="var(--surface-2)" stroke="var(--border)" stroke-width="2"/><path d="m115 65 22 13q7 5 3 11l-3 5q-3 4-8 1l-22-14" fill="var(--surface-2)" stroke="var(--border-strong)" stroke-width="3"/><path d="m126 27 5-9m7 17 10-4m-7 14 10 2" stroke="var(--brand)" stroke-opacity=".35" stroke-width="3" stroke-linecap="round"/></svg><span>No audio messages found.</span></td></tr></tbody></table></div>
        <div class="set-calling-filter-pop" data-audio-filter-pop="type" hidden><label class="set-calling-filter-search"><input type="search" placeholder="Type to search" data-audio-type-search aria-label="Search message types"></label><div data-audio-type-options><button type="button" data-audio-type-option="IVR">IVR</button><button type="button" data-audio-type-option="Voicemail">Voicemail</button><button type="button" data-audio-type-option="Recording Consent">Recording Consent</button><button type="button" data-audio-type-option="Voicemail Drop">Voicemail Drop</button><button type="button" data-audio-type-option="Hold Music">Hold Music</button><button type="button" data-audio-type-option="Hold Message">Hold Message</button><button type="button" data-audio-type-option="Callback Offer">Callback Offer</button><button type="button" data-audio-type-option="Callback Greeting">Callback Greeting</button><button type="button" data-audio-type-option="Callback Confirmation">Callback Confirmation</button></div></div>
        <div class="set-calling-filter-pop set-calling-created-pop" data-audio-filter-pop="created" hidden><label class="set-calling-filter-search"><input type="search" placeholder="Type to search" data-audio-created-search aria-label="Search creators"></label><div data-audio-created-options></div></div>
      </div>
    </div>
  </dialog>

  <!-- Theme modal: register phone number -->
  <dialog class="set-modal set-calling-phone-modal" id="call-phone-dialog" aria-labelledby="call-phone-title">
    <div class="set-modal__head"><h2 class="set-modal__title" id="call-phone-title">Add your phone number</h2><button type="button" class="icon-btn" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-16'); ?></button></div>
    <div class="set-modal__body">
      <form data-phone-form>
        <div data-phone-step="1">
          <h3 class="set-calling-step-title">Enter your phone number</h3>
          <p class="set-calling-modal-intro">To verify your phone number, you'll receive a code via SMS message or phone call.</p>
          <div class="set-calling-phone-fields">
            <div class="custom-select-wrapper set-calling-country-select" data-country-picker>
              <button type="button" class="custom-select__trigger" data-country-trigger aria-haspopup="listbox" aria-expanded="false"><span data-country-current>US</span><svg class="set-calling-caret-svg" viewBox="0 0 16 16" width="14" height="14" fill="none" aria-hidden="true"><path d="m4 6 4 4 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
              <div class="custom-select__dropdown" data-country-dropdown hidden>
                <div class="custom-select__search"><input type="search" placeholder="Search" aria-label="Search countries" data-country-search autocomplete="off"></div>
                <div class="custom-select__options" role="listbox" aria-label="Country calling codes" data-country-options><button type="button" class="custom-select__option" role="option" data-country-option="US" data-country-search-text="us united states +1" data-dial="+1"><span>US&nbsp;&nbsp;United States</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CA" data-country-search-text="ca canada +1" data-dial="+1"><span>CA&nbsp;&nbsp;Canada</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GB" data-country-search-text="gb united kingdom +44" data-dial="+44"><span>GB&nbsp;&nbsp;United Kingdom</span><span>+44</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IN" data-country-search-text="in india +91" data-dial="+91"><span>IN&nbsp;&nbsp;India</span><span>+91</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AU" data-country-search-text="au australia +61" data-dial="+61"><span>AU&nbsp;&nbsp;Australia</span><span>+61</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NZ" data-country-search-text="nz new zealand +64" data-dial="+64"><span>NZ&nbsp;&nbsp;New Zealand</span><span>+64</span></button><button type="button" class="custom-select__option" role="option" data-country-option="FR" data-country-search-text="fr france +33" data-dial="+33"><span>FR&nbsp;&nbsp;France</span><span>+33</span></button><button type="button" class="custom-select__option" role="option" data-country-option="DE" data-country-search-text="de germany +49" data-dial="+49"><span>DE&nbsp;&nbsp;Germany</span><span>+49</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IT" data-country-search-text="it italy +39" data-dial="+39"><span>IT&nbsp;&nbsp;Italy</span><span>+39</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ES" data-country-search-text="es spain +34" data-dial="+34"><span>ES&nbsp;&nbsp;Spain</span><span>+34</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PT" data-country-search-text="pt portugal +351" data-dial="+351"><span>PT&nbsp;&nbsp;Portugal</span><span>+351</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NL" data-country-search-text="nl netherlands +31" data-dial="+31"><span>NL&nbsp;&nbsp;Netherlands</span><span>+31</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BE" data-country-search-text="be belgium +32" data-dial="+32"><span>BE&nbsp;&nbsp;Belgium</span><span>+32</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CH" data-country-search-text="ch switzerland +41" data-dial="+41"><span>CH&nbsp;&nbsp;Switzerland</span><span>+41</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AT" data-country-search-text="at austria +43" data-dial="+43"><span>AT&nbsp;&nbsp;Austria</span><span>+43</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IE" data-country-search-text="ie ireland +353" data-dial="+353"><span>IE&nbsp;&nbsp;Ireland</span><span>+353</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SE" data-country-search-text="se sweden +46" data-dial="+46"><span>SE&nbsp;&nbsp;Sweden</span><span>+46</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NO" data-country-search-text="no norway +47" data-dial="+47"><span>NO&nbsp;&nbsp;Norway</span><span>+47</span></button><button type="button" class="custom-select__option" role="option" data-country-option="DK" data-country-search-text="dk denmark +45" data-dial="+45"><span>DK&nbsp;&nbsp;Denmark</span><span>+45</span></button><button type="button" class="custom-select__option" role="option" data-country-option="FI" data-country-search-text="fi finland +358" data-dial="+358"><span>FI&nbsp;&nbsp;Finland</span><span>+358</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IS" data-country-search-text="is iceland +354" data-dial="+354"><span>IS&nbsp;&nbsp;Iceland</span><span>+354</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PL" data-country-search-text="pl poland +48" data-dial="+48"><span>PL&nbsp;&nbsp;Poland</span><span>+48</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CZ" data-country-search-text="cz czechia +420" data-dial="+420"><span>CZ&nbsp;&nbsp;Czechia</span><span>+420</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SK" data-country-search-text="sk slovakia +421" data-dial="+421"><span>SK&nbsp;&nbsp;Slovakia</span><span>+421</span></button><button type="button" class="custom-select__option" role="option" data-country-option="HU" data-country-search-text="hu hungary +36" data-dial="+36"><span>HU&nbsp;&nbsp;Hungary</span><span>+36</span></button><button type="button" class="custom-select__option" role="option" data-country-option="RO" data-country-search-text="ro romania +40" data-dial="+40"><span>RO&nbsp;&nbsp;Romania</span><span>+40</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BG" data-country-search-text="bg bulgaria +359" data-dial="+359"><span>BG&nbsp;&nbsp;Bulgaria</span><span>+359</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GR" data-country-search-text="gr greece +30" data-dial="+30"><span>GR&nbsp;&nbsp;Greece</span><span>+30</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TR" data-country-search-text="tr türkiye +90" data-dial="+90"><span>TR&nbsp;&nbsp;Türkiye</span><span>+90</span></button><button type="button" class="custom-select__option" role="option" data-country-option="UA" data-country-search-text="ua ukraine +380" data-dial="+380"><span>UA&nbsp;&nbsp;Ukraine</span><span>+380</span></button><button type="button" class="custom-select__option" role="option" data-country-option="RU" data-country-search-text="ru russia +7" data-dial="+7"><span>RU&nbsp;&nbsp;Russia</span><span>+7</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CN" data-country-search-text="cn china +86" data-dial="+86"><span>CN&nbsp;&nbsp;China</span><span>+86</span></button><button type="button" class="custom-select__option" role="option" data-country-option="JP" data-country-search-text="jp japan +81" data-dial="+81"><span>JP&nbsp;&nbsp;Japan</span><span>+81</span></button><button type="button" class="custom-select__option" role="option" data-country-option="KR" data-country-search-text="kr south korea +82" data-dial="+82"><span>KR&nbsp;&nbsp;South Korea</span><span>+82</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SG" data-country-search-text="sg singapore +65" data-dial="+65"><span>SG&nbsp;&nbsp;Singapore</span><span>+65</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MY" data-country-search-text="my malaysia +60" data-dial="+60"><span>MY&nbsp;&nbsp;Malaysia</span><span>+60</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ID" data-country-search-text="id indonesia +62" data-dial="+62"><span>ID&nbsp;&nbsp;Indonesia</span><span>+62</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PH" data-country-search-text="ph philippines +63" data-dial="+63"><span>PH&nbsp;&nbsp;Philippines</span><span>+63</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TH" data-country-search-text="th thailand +66" data-dial="+66"><span>TH&nbsp;&nbsp;Thailand</span><span>+66</span></button><button type="button" class="custom-select__option" role="option" data-country-option="VN" data-country-search-text="vn vietnam +84" data-dial="+84"><span>VN&nbsp;&nbsp;Vietnam</span><span>+84</span></button><button type="button" class="custom-select__option" role="option" data-country-option="HK" data-country-search-text="hk hong kong +852" data-dial="+852"><span>HK&nbsp;&nbsp;Hong Kong</span><span>+852</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TW" data-country-search-text="tw taiwan +886" data-dial="+886"><span>TW&nbsp;&nbsp;Taiwan</span><span>+886</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PK" data-country-search-text="pk pakistan +92" data-dial="+92"><span>PK&nbsp;&nbsp;Pakistan</span><span>+92</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BD" data-country-search-text="bd bangladesh +880" data-dial="+880"><span>BD&nbsp;&nbsp;Bangladesh</span><span>+880</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LK" data-country-search-text="lk sri lanka +94" data-dial="+94"><span>LK&nbsp;&nbsp;Sri Lanka</span><span>+94</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NP" data-country-search-text="np nepal +977" data-dial="+977"><span>NP&nbsp;&nbsp;Nepal</span><span>+977</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AE" data-country-search-text="ae united arab emirates +971" data-dial="+971"><span>AE&nbsp;&nbsp;United Arab Emirates</span><span>+971</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SA" data-country-search-text="sa saudi arabia +966" data-dial="+966"><span>SA&nbsp;&nbsp;Saudi Arabia</span><span>+966</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IL" data-country-search-text="il israel +972" data-dial="+972"><span>IL&nbsp;&nbsp;Israel</span><span>+972</span></button><button type="button" class="custom-select__option" role="option" data-country-option="QA" data-country-search-text="qa qatar +974" data-dial="+974"><span>QA&nbsp;&nbsp;Qatar</span><span>+974</span></button><button type="button" class="custom-select__option" role="option" data-country-option="KW" data-country-search-text="kw kuwait +965" data-dial="+965"><span>KW&nbsp;&nbsp;Kuwait</span><span>+965</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BH" data-country-search-text="bh bahrain +973" data-dial="+973"><span>BH&nbsp;&nbsp;Bahrain</span><span>+973</span></button><button type="button" class="custom-select__option" role="option" data-country-option="OM" data-country-search-text="om oman +968" data-dial="+968"><span>OM&nbsp;&nbsp;Oman</span><span>+968</span></button><button type="button" class="custom-select__option" role="option" data-country-option="JO" data-country-search-text="jo jordan +962" data-dial="+962"><span>JO&nbsp;&nbsp;Jordan</span><span>+962</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LB" data-country-search-text="lb lebanon +961" data-dial="+961"><span>LB&nbsp;&nbsp;Lebanon</span><span>+961</span></button><button type="button" class="custom-select__option" role="option" data-country-option="EG" data-country-search-text="eg egypt +20" data-dial="+20"><span>EG&nbsp;&nbsp;Egypt</span><span>+20</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ZA" data-country-search-text="za south africa +27" data-dial="+27"><span>ZA&nbsp;&nbsp;South Africa</span><span>+27</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NG" data-country-search-text="ng nigeria +234" data-dial="+234"><span>NG&nbsp;&nbsp;Nigeria</span><span>+234</span></button><button type="button" class="custom-select__option" role="option" data-country-option="KE" data-country-search-text="ke kenya +254" data-dial="+254"><span>KE&nbsp;&nbsp;Kenya</span><span>+254</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GH" data-country-search-text="gh ghana +233" data-dial="+233"><span>GH&nbsp;&nbsp;Ghana</span><span>+233</span></button><button type="button" class="custom-select__option" role="option" data-country-option="UG" data-country-search-text="ug uganda +256" data-dial="+256"><span>UG&nbsp;&nbsp;Uganda</span><span>+256</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TZ" data-country-search-text="tz tanzania +255" data-dial="+255"><span>TZ&nbsp;&nbsp;Tanzania</span><span>+255</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MA" data-country-search-text="ma morocco +212" data-dial="+212"><span>MA&nbsp;&nbsp;Morocco</span><span>+212</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TN" data-country-search-text="tn tunisia +216" data-dial="+216"><span>TN&nbsp;&nbsp;Tunisia</span><span>+216</span></button><button type="button" class="custom-select__option" role="option" data-country-option="DZ" data-country-search-text="dz algeria +213" data-dial="+213"><span>DZ&nbsp;&nbsp;Algeria</span><span>+213</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ET" data-country-search-text="et ethiopia +251" data-dial="+251"><span>ET&nbsp;&nbsp;Ethiopia</span><span>+251</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BR" data-country-search-text="br brazil +55" data-dial="+55"><span>BR&nbsp;&nbsp;Brazil</span><span>+55</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MX" data-country-search-text="mx mexico +52" data-dial="+52"><span>MX&nbsp;&nbsp;Mexico</span><span>+52</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AR" data-country-search-text="ar argentina +54" data-dial="+54"><span>AR&nbsp;&nbsp;Argentina</span><span>+54</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CL" data-country-search-text="cl chile +56" data-dial="+56"><span>CL&nbsp;&nbsp;Chile</span><span>+56</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CO" data-country-search-text="co colombia +57" data-dial="+57"><span>CO&nbsp;&nbsp;Colombia</span><span>+57</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PE" data-country-search-text="pe peru +51" data-dial="+51"><span>PE&nbsp;&nbsp;Peru</span><span>+51</span></button><button type="button" class="custom-select__option" role="option" data-country-option="VE" data-country-search-text="ve venezuela +58" data-dial="+58"><span>VE&nbsp;&nbsp;Venezuela</span><span>+58</span></button><button type="button" class="custom-select__option" role="option" data-country-option="UY" data-country-search-text="uy uruguay +598" data-dial="+598"><span>UY&nbsp;&nbsp;Uruguay</span><span>+598</span></button><button type="button" class="custom-select__option" role="option" data-country-option="EC" data-country-search-text="ec ecuador +593" data-dial="+593"><span>EC&nbsp;&nbsp;Ecuador</span><span>+593</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CR" data-country-search-text="cr costa rica +506" data-dial="+506"><span>CR&nbsp;&nbsp;Costa Rica</span><span>+506</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PA" data-country-search-text="pa panama +507" data-dial="+507"><span>PA&nbsp;&nbsp;Panama</span><span>+507</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GT" data-country-search-text="gt guatemala +502" data-dial="+502"><span>GT&nbsp;&nbsp;Guatemala</span><span>+502</span></button><button type="button" class="custom-select__option" role="option" data-country-option="DO" data-country-search-text="do dominican republic +1" data-dial="+1"><span>DO&nbsp;&nbsp;Dominican Republic</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="JM" data-country-search-text="jm jamaica +1" data-dial="+1"><span>JM&nbsp;&nbsp;Jamaica</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="TT" data-country-search-text="tt trinidad and tobago +1" data-dial="+1"><span>TT&nbsp;&nbsp;Trinidad and Tobago</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BS" data-country-search-text="bs bahamas +1" data-dial="+1"><span>BS&nbsp;&nbsp;Bahamas</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BB" data-country-search-text="bb barbados +1" data-dial="+1"><span>BB&nbsp;&nbsp;Barbados</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PR" data-country-search-text="pr puerto rico +1" data-dial="+1"><span>PR&nbsp;&nbsp;Puerto Rico</span><span>+1</span></button><button type="button" class="custom-select__option" role="option" data-country-option="KZ" data-country-search-text="kz kazakhstan +7" data-dial="+7"><span>KZ&nbsp;&nbsp;Kazakhstan</span><span>+7</span></button><button type="button" class="custom-select__option" role="option" data-country-option="UZ" data-country-search-text="uz uzbekistan +998" data-dial="+998"><span>UZ&nbsp;&nbsp;Uzbekistan</span><span>+998</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GE" data-country-search-text="ge georgia +995" data-dial="+995"><span>GE&nbsp;&nbsp;Georgia</span><span>+995</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AM" data-country-search-text="am armenia +374" data-dial="+374"><span>AM&nbsp;&nbsp;Armenia</span><span>+374</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AZ" data-country-search-text="az azerbaijan +994" data-dial="+994"><span>AZ&nbsp;&nbsp;Azerbaijan</span><span>+994</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AF" data-country-search-text="af afghanistan +93" data-dial="+93"><span>AF&nbsp;&nbsp;Afghanistan</span><span>+93</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IR" data-country-search-text="ir iran +98" data-dial="+98"><span>IR&nbsp;&nbsp;Iran</span><span>+98</span></button><button type="button" class="custom-select__option" role="option" data-country-option="IQ" data-country-search-text="iq iraq +964" data-dial="+964"><span>IQ&nbsp;&nbsp;Iraq</span><span>+964</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SY" data-country-search-text="sy syria +963" data-dial="+963"><span>SY&nbsp;&nbsp;Syria</span><span>+963</span></button><button type="button" class="custom-select__option" role="option" data-country-option="YE" data-country-search-text="ye yemen +967" data-dial="+967"><span>YE&nbsp;&nbsp;Yemen</span><span>+967</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MM" data-country-search-text="mm myanmar +95" data-dial="+95"><span>MM&nbsp;&nbsp;Myanmar</span><span>+95</span></button><button type="button" class="custom-select__option" role="option" data-country-option="KH" data-country-search-text="kh cambodia +855" data-dial="+855"><span>KH&nbsp;&nbsp;Cambodia</span><span>+855</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LA" data-country-search-text="la laos +856" data-dial="+856"><span>LA&nbsp;&nbsp;Laos</span><span>+856</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MN" data-country-search-text="mn mongolia +976" data-dial="+976"><span>MN&nbsp;&nbsp;Mongolia</span><span>+976</span></button><button type="button" class="custom-select__option" role="option" data-country-option="FJ" data-country-search-text="fj fiji +679" data-dial="+679"><span>FJ&nbsp;&nbsp;Fiji</span><span>+679</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PG" data-country-search-text="pg papua new guinea +675" data-dial="+675"><span>PG&nbsp;&nbsp;Papua New Guinea</span><span>+675</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CY" data-country-search-text="cy cyprus +357" data-dial="+357"><span>CY&nbsp;&nbsp;Cyprus</span><span>+357</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MT" data-country-search-text="mt malta +356" data-dial="+356"><span>MT&nbsp;&nbsp;Malta</span><span>+356</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LU" data-country-search-text="lu luxembourg +352" data-dial="+352"><span>LU&nbsp;&nbsp;Luxembourg</span><span>+352</span></button><button type="button" class="custom-select__option" role="option" data-country-option="HR" data-country-search-text="hr croatia +385" data-dial="+385"><span>HR&nbsp;&nbsp;Croatia</span><span>+385</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SI" data-country-search-text="si slovenia +386" data-dial="+386"><span>SI&nbsp;&nbsp;Slovenia</span><span>+386</span></button><button type="button" class="custom-select__option" role="option" data-country-option="RS" data-country-search-text="rs serbia +381" data-dial="+381"><span>RS&nbsp;&nbsp;Serbia</span><span>+381</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BA" data-country-search-text="ba bosnia and herzegovina +387" data-dial="+387"><span>BA&nbsp;&nbsp;Bosnia and Herzegovina</span><span>+387</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ME" data-country-search-text="me montenegro +382" data-dial="+382"><span>ME&nbsp;&nbsp;Montenegro</span><span>+382</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AL" data-country-search-text="al albania +355" data-dial="+355"><span>AL&nbsp;&nbsp;Albania</span><span>+355</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MK" data-country-search-text="mk north macedonia +389" data-dial="+389"><span>MK&nbsp;&nbsp;North Macedonia</span><span>+389</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LT" data-country-search-text="lt lithuania +370" data-dial="+370"><span>LT&nbsp;&nbsp;Lithuania</span><span>+370</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LV" data-country-search-text="lv latvia +371" data-dial="+371"><span>LV&nbsp;&nbsp;Latvia</span><span>+371</span></button><button type="button" class="custom-select__option" role="option" data-country-option="EE" data-country-search-text="ee estonia +372" data-dial="+372"><span>EE&nbsp;&nbsp;Estonia</span><span>+372</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MD" data-country-search-text="md moldova +373" data-dial="+373"><span>MD&nbsp;&nbsp;Moldova</span><span>+373</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BY" data-country-search-text="by belarus +375" data-dial="+375"><span>BY&nbsp;&nbsp;Belarus</span><span>+375</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SN" data-country-search-text="sn senegal +221" data-dial="+221"><span>SN&nbsp;&nbsp;Senegal</span><span>+221</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CI" data-country-search-text="ci côte d’ivoire +225" data-dial="+225"><span>CI&nbsp;&nbsp;Côte d’Ivoire</span><span>+225</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CM" data-country-search-text="cm cameroon +237" data-dial="+237"><span>CM&nbsp;&nbsp;Cameroon</span><span>+237</span></button><button type="button" class="custom-select__option" role="option" data-country-option="AO" data-country-search-text="ao angola +244" data-dial="+244"><span>AO&nbsp;&nbsp;Angola</span><span>+244</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ZM" data-country-search-text="zm zambia +260" data-dial="+260"><span>ZM&nbsp;&nbsp;Zambia</span><span>+260</span></button><button type="button" class="custom-select__option" role="option" data-country-option="ZW" data-country-search-text="zw zimbabwe +263" data-dial="+263"><span>ZW&nbsp;&nbsp;Zimbabwe</span><span>+263</span></button><button type="button" class="custom-select__option" role="option" data-country-option="MU" data-country-search-text="mu mauritius +230" data-dial="+230"><span>MU&nbsp;&nbsp;Mauritius</span><span>+230</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BW" data-country-search-text="bw botswana +267" data-dial="+267"><span>BW&nbsp;&nbsp;Botswana</span><span>+267</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NA" data-country-search-text="na namibia +264" data-dial="+264"><span>NA&nbsp;&nbsp;Namibia</span><span>+264</span></button><button type="button" class="custom-select__option" role="option" data-country-option="RW" data-country-search-text="rw rwanda +250" data-dial="+250"><span>RW&nbsp;&nbsp;Rwanda</span><span>+250</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SD" data-country-search-text="sd sudan +249" data-dial="+249"><span>SD&nbsp;&nbsp;Sudan</span><span>+249</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SS" data-country-search-text="ss south sudan +211" data-dial="+211"><span>SS&nbsp;&nbsp;South Sudan</span><span>+211</span></button><button type="button" class="custom-select__option" role="option" data-country-option="LY" data-country-search-text="ly libya +218" data-dial="+218"><span>LY&nbsp;&nbsp;Libya</span><span>+218</span></button><button type="button" class="custom-select__option" role="option" data-country-option="CU" data-country-search-text="cu cuba +53" data-dial="+53"><span>CU&nbsp;&nbsp;Cuba</span><span>+53</span></button><button type="button" class="custom-select__option" role="option" data-country-option="HT" data-country-search-text="ht haiti +509" data-dial="+509"><span>HT&nbsp;&nbsp;Haiti</span><span>+509</span></button><button type="button" class="custom-select__option" role="option" data-country-option="HN" data-country-search-text="hn honduras +504" data-dial="+504"><span>HN&nbsp;&nbsp;Honduras</span><span>+504</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SV" data-country-search-text="sv el salvador +503" data-dial="+503"><span>SV&nbsp;&nbsp;El Salvador</span><span>+503</span></button><button type="button" class="custom-select__option" role="option" data-country-option="NI" data-country-search-text="ni nicaragua +505" data-dial="+505"><span>NI&nbsp;&nbsp;Nicaragua</span><span>+505</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BZ" data-country-search-text="bz belize +501" data-dial="+501"><span>BZ&nbsp;&nbsp;Belize</span><span>+501</span></button><button type="button" class="custom-select__option" role="option" data-country-option="GY" data-country-search-text="gy guyana +592" data-dial="+592"><span>GY&nbsp;&nbsp;Guyana</span><span>+592</span></button><button type="button" class="custom-select__option" role="option" data-country-option="SR" data-country-search-text="sr suriname +597" data-dial="+597"><span>SR&nbsp;&nbsp;Suriname</span><span>+597</span></button><button type="button" class="custom-select__option" role="option" data-country-option="BO" data-country-search-text="bo bolivia +591" data-dial="+591"><span>BO&nbsp;&nbsp;Bolivia</span><span>+591</span></button><button type="button" class="custom-select__option" role="option" data-country-option="PY" data-country-search-text="py paraguay +595" data-dial="+595"><span>PY&nbsp;&nbsp;Paraguay</span><span>+595</span></button></div>
              </div>
              <select class="input" name="phone_country" aria-label="Country code" hidden><option value="US" data-dial="+1" selected>US</option><option value="CA" data-dial="+1">CA</option><option value="GB" data-dial="+44">GB</option><option value="IN" data-dial="+91">IN</option><option value="AU" data-dial="+61">AU</option><option value="NZ" data-dial="+64">NZ</option><option value="FR" data-dial="+33">FR</option><option value="DE" data-dial="+49">DE</option><option value="IT" data-dial="+39">IT</option><option value="ES" data-dial="+34">ES</option><option value="PT" data-dial="+351">PT</option><option value="NL" data-dial="+31">NL</option><option value="BE" data-dial="+32">BE</option><option value="CH" data-dial="+41">CH</option><option value="AT" data-dial="+43">AT</option><option value="IE" data-dial="+353">IE</option><option value="SE" data-dial="+46">SE</option><option value="NO" data-dial="+47">NO</option><option value="DK" data-dial="+45">DK</option><option value="FI" data-dial="+358">FI</option><option value="IS" data-dial="+354">IS</option><option value="PL" data-dial="+48">PL</option><option value="CZ" data-dial="+420">CZ</option><option value="SK" data-dial="+421">SK</option><option value="HU" data-dial="+36">HU</option><option value="RO" data-dial="+40">RO</option><option value="BG" data-dial="+359">BG</option><option value="GR" data-dial="+30">GR</option><option value="TR" data-dial="+90">TR</option><option value="UA" data-dial="+380">UA</option><option value="RU" data-dial="+7">RU</option><option value="CN" data-dial="+86">CN</option><option value="JP" data-dial="+81">JP</option><option value="KR" data-dial="+82">KR</option><option value="SG" data-dial="+65">SG</option><option value="MY" data-dial="+60">MY</option><option value="ID" data-dial="+62">ID</option><option value="PH" data-dial="+63">PH</option><option value="TH" data-dial="+66">TH</option><option value="VN" data-dial="+84">VN</option><option value="HK" data-dial="+852">HK</option><option value="TW" data-dial="+886">TW</option><option value="PK" data-dial="+92">PK</option><option value="BD" data-dial="+880">BD</option><option value="LK" data-dial="+94">LK</option><option value="NP" data-dial="+977">NP</option><option value="AE" data-dial="+971">AE</option><option value="SA" data-dial="+966">SA</option><option value="IL" data-dial="+972">IL</option><option value="QA" data-dial="+974">QA</option><option value="KW" data-dial="+965">KW</option><option value="BH" data-dial="+973">BH</option><option value="OM" data-dial="+968">OM</option><option value="JO" data-dial="+962">JO</option><option value="LB" data-dial="+961">LB</option><option value="EG" data-dial="+20">EG</option><option value="ZA" data-dial="+27">ZA</option><option value="NG" data-dial="+234">NG</option><option value="KE" data-dial="+254">KE</option><option value="GH" data-dial="+233">GH</option><option value="UG" data-dial="+256">UG</option><option value="TZ" data-dial="+255">TZ</option><option value="MA" data-dial="+212">MA</option><option value="TN" data-dial="+216">TN</option><option value="DZ" data-dial="+213">DZ</option><option value="ET" data-dial="+251">ET</option><option value="BR" data-dial="+55">BR</option><option value="MX" data-dial="+52">MX</option><option value="AR" data-dial="+54">AR</option><option value="CL" data-dial="+56">CL</option><option value="CO" data-dial="+57">CO</option><option value="PE" data-dial="+51">PE</option><option value="VE" data-dial="+58">VE</option><option value="UY" data-dial="+598">UY</option><option value="EC" data-dial="+593">EC</option><option value="CR" data-dial="+506">CR</option><option value="PA" data-dial="+507">PA</option><option value="GT" data-dial="+502">GT</option><option value="DO" data-dial="+1">DO</option><option value="JM" data-dial="+1">JM</option><option value="TT" data-dial="+1">TT</option><option value="BS" data-dial="+1">BS</option><option value="BB" data-dial="+1">BB</option><option value="PR" data-dial="+1">PR</option><option value="KZ" data-dial="+7">KZ</option><option value="UZ" data-dial="+998">UZ</option><option value="GE" data-dial="+995">GE</option><option value="AM" data-dial="+374">AM</option><option value="AZ" data-dial="+994">AZ</option><option value="AF" data-dial="+93">AF</option><option value="IR" data-dial="+98">IR</option><option value="IQ" data-dial="+964">IQ</option><option value="SY" data-dial="+963">SY</option><option value="YE" data-dial="+967">YE</option><option value="MM" data-dial="+95">MM</option><option value="KH" data-dial="+855">KH</option><option value="LA" data-dial="+856">LA</option><option value="MN" data-dial="+976">MN</option><option value="FJ" data-dial="+679">FJ</option><option value="PG" data-dial="+675">PG</option><option value="CY" data-dial="+357">CY</option><option value="MT" data-dial="+356">MT</option><option value="LU" data-dial="+352">LU</option><option value="HR" data-dial="+385">HR</option><option value="SI" data-dial="+386">SI</option><option value="RS" data-dial="+381">RS</option><option value="BA" data-dial="+387">BA</option><option value="ME" data-dial="+382">ME</option><option value="AL" data-dial="+355">AL</option><option value="MK" data-dial="+389">MK</option><option value="LT" data-dial="+370">LT</option><option value="LV" data-dial="+371">LV</option><option value="EE" data-dial="+372">EE</option><option value="MD" data-dial="+373">MD</option><option value="BY" data-dial="+375">BY</option><option value="SN" data-dial="+221">SN</option><option value="CI" data-dial="+225">CI</option><option value="CM" data-dial="+237">CM</option><option value="AO" data-dial="+244">AO</option><option value="ZM" data-dial="+260">ZM</option><option value="ZW" data-dial="+263">ZW</option><option value="MU" data-dial="+230">MU</option><option value="BW" data-dial="+267">BW</option><option value="NA" data-dial="+264">NA</option><option value="RW" data-dial="+250">RW</option><option value="SD" data-dial="+249">SD</option><option value="SS" data-dial="+211">SS</option><option value="LY" data-dial="+218">LY</option><option value="CU" data-dial="+53">CU</option><option value="HT" data-dial="+509">HT</option><option value="HN" data-dial="+504">HN</option><option value="SV" data-dial="+503">SV</option><option value="NI" data-dial="+505">NI</option><option value="BZ" data-dial="+501">BZ</option><option value="GY" data-dial="+592">GY</option><option value="SR" data-dial="+597">SR</option><option value="BO" data-dial="+591">BO</option><option value="PY" data-dial="+595">PY</option></select>
            </div>
            <input class="input" name="phone_number" type="tel" placeholder="+1" aria-label="Phone number" required>
            <input class="input" name="phone_extension" placeholder="Extension" aria-label="Extension">
          </div>
          <p class="set-calling-phone-error" data-phone-error hidden>Please enter a valid phone number.</p>
          <fieldset class="set-calling-radio-field"><legend>Receive the code by (data rates apply):</legend><label class="set-calling-radio"><input type="radio" name="verification_method" value="sms" checked><span>SMS message</span></label><label class="set-calling-radio"><input type="radio" name="verification_method" value="call"><span>Phone call</span></label></fieldset>
        </div>
        <div data-phone-step="2" hidden><h3 class="set-calling-step-title">Verify your phone number</h3><p class="set-calling-modal-intro">Enter the verification code sent to your phone.</p><label class="field__label" for="phone-verification-code">Verification code</label><input class="input" id="phone-verification-code" name="verification_code" inputmode="numeric" maxlength="6" placeholder="Enter code"><p class="field__help">Demo flow: enter any 4–6 digit code to continue.</p></div>
        <div data-phone-step="3" hidden><h3 class="set-calling-step-title">Phone number added</h3><p class="set-calling-modal-intro">Your phone number has been verified and added for outbound calling.</p></div>
        <div class="set-calling-phone-footer"><button type="button" class="btn-crm btn-crm--outline" data-phone-cancel>Cancel</button><span class="set-calling-step-count" data-phone-step-count>1/3</span><button type="button" class="btn-crm btn-crm--primary" data-phone-next disabled>Text me</button></div>
      </form>
    </div>
  </dialog>
</section>

<!-- ========================================================= CALENDAR -->
    <section id="tab-calendar" class="crm-d-none" role="tabpanel">
      <p class="set-preferences-note">These preferences only apply to you.</p>
      <div class="set-calendar-access"><strong>Need access to connect your calendar?</strong><span>Ask an account admin to update your permissions.</span><a href="#" data-calendar-learn>Learn more ↗</a></div>
      <form class="set-calendar-form" data-settings-form novalidate>
        <section class="set-calendar-section set-calendar-intro">
          <div class="set-calendar-copy"><h2 class="set-card__title">Calendar</h2><p class="set-calendar-description">Connect your calendar to use CRM Meetings and calendar sync.</p>
            <ul class="set-calendar-checklist">
              <li><svg class="set-calendar-tick" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="m3.25 8.25 3.1 3.1 6.4-6.7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Send meetings directly from CRM</span></li><li><svg class="set-calendar-tick" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="m3.25 8.25 3.1 3.1 6.4-6.7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Log outgoing meetings automatically</span></li>
              <li><svg class="set-calendar-tick" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="m3.25 8.25 3.1 3.1 6.4-6.7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg><span>Sync your calendar so contacts can schedule time with you <small>Requires Calendar Sync</small></span></li>
              <li><svg class="set-calendar-tick" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="m3.25 8.25 3.1 3.1 6.4-6.7" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/></svg><span>See your CRM tasks in your calendar <small>Requires an additional step with task sync. Only available on Sales Starter and up plans.</small></span></li>
            </ul><button type="button" class="btn-crm btn-crm--outline set-calendar-connect" disabled aria-disabled="true">Connect your calendar</button>
          </div><div class="set-calendar-art" aria-hidden="true">
           <img src="assets/img/crm-calendar.svg" width="150">
          </div>
        </section>
        <section class="set-calendar-section">
          <h2 class="set-card__title set-calendar-disabled-heading">Notetaker settings <svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M6.1 9.9 9.9 6.1M5.2 5.2a3.4 3.4 0 0 1 4.8 0l.8.8M10.8 10.8a3.4 3.4 0 0 1-4.8 0l-.8-.8M2.2 2.2l11.6 11.6" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg></h2><p class="set-calendar-description">Manage how Notetaker works for meetings you own.</p>
          <label class="check set-calendar-check set-calendar-check--disabled" aria-disabled="true"><input type="checkbox" name="notetaker_auto_join" disabled><span class="check__box" aria-hidden="true"></span><span><strong>Notetaker auto-join</strong><small>Invite notetaker to join all your upcoming meetings automatically.</small></span></label>
          <div class="set-calendar-domain-block is-disabled" aria-disabled="true"><strong>Domain and email auto exclusions</strong><p>Add specific email addresses or domains that the notetaker should never auto-join. Notetaker will be turned off by default for meetings with these emails or domains.</p><div class="set-calendar-exclusions" data-calendar-exclusions></div><button type="button" class="btn-crm btn-crm--outline set-calendar-add" data-calendar-add-exclusion disabled aria-disabled="true">＋ Domain or email</button></div>
        </section>
        <section class="set-calendar-section">
          <h2 class="set-card__title">Meetings</h2><p class="set-calendar-description">Customize your CRM Meetings URL and domain.</p>
          <div class="set-calendar-field"><label class="field__label" for="calendar-meetings-url">Meetings URL</label><p class="field__help">Your new meetings URL will only apply to future meetings and won't affect links created before.</p><div class="set-calendar-url"><span>meetings.CRM.com/</span><input class="input" id="calendar-meetings-url" name="meetings_url" value="your-name"></div></div>
          <div class="set-calendar-field"><label class="field__label" for="calendar-domain">Meeting domain</label><p class="field__help">Previously sent links are still accessible from their old locations.</p><div class="custom-select-wrapper set-calendar-disabled-select" data-custom-select data-type="single" aria-disabled="true"><select id="calendar-domain" name="meeting_domain" disabled hidden><option selected>No custom domains available</option></select></div><button type="button" class="set-calendar-text-button" data-calendar-clear-domain disabled aria-disabled="true">Clear custom domain</button></div>
          <div class="set-calendar-field"><label class="field__label" for="calendar-default-link">Default meeting link</label><p class="field__help">The default meeting link is used for personalization tokens and can't be deleted.</p><div class="custom-select-wrapper" data-custom-select data-type="single"><select id="calendar-default-link" name="default_meeting_link" hidden><option selected>60 min, 30 min, and 15 min meeting</option><option>60 min meeting</option><option>30 min meeting</option><option>15 min meeting</option></select></div></div>
          <div class="set-calendar-field"><label class="field__label">Scheduling pages</label><p class="field__help">You can turn off this feature, which will disable all scheduling pages owned by your user.</p><button type="button" class="btn-crm btn-crm--outline" data-calendar-turnoff>Turn off</button></div>
        </section>
        <section class="set-calendar-section"><h2 class="set-card__title">Chat Profile</h2>
          <label class="check set-calendar-check set-calendar-check--inline"><input type="checkbox" name="chat_profile_enabled" checked data-chat-profile-toggle><span class="check__box" aria-hidden="true"></span><span>Include a link to your meetings booking page in the messages chat window</span></label>
          <div class="set-calendar-field set-calendar-chat-fields" data-chat-profile-fields><label class="field__label crm-me-2" for="calendar-chat-link">Chat Meeting Link</label><div class="custom-select-wrapper" data-custom-select data-type="single"><select id="calendar-chat-link" name="chat_meeting_link" hidden><option selected>60 min, 30 min, and 15 min meeting</option><option>60 min meeting</option><option>30 min meeting</option><option>15 min meeting</option></select></div></div>
          <div class="set-calendar-field set-calendar-chat-fields" data-chat-profile-fields><label class="field__label crm-mb-2 crm-d-block" for="calendar-custom-link-text">Custom Meeting Link Text</label><input class="input" id="calendar-custom-link-text" name="custom_meeting_link_text" value=""></div>
        </section>
      </form>
      <dialog class="set-modal set-calendar-confirm" id="calendar-turnoff-dialog"><div class="set-calendar-confirm-head"><button type="button" class="icon-btn icon-btn--ghost set-calendar-x" data-calendar-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button><h2>Are you sure you want to turn off meeting scheduling pages?</h2></div><div class="set-calendar-confirm-body"><p>When you turn off this feature, all scheduling pages owned by your user will be disabled. Meeting links will no longer be accessible. This includes any meeting link that may be shown on your website, in your email signatures, or anywhere else a link to a scheduling page might have been placed. Navigating to one of these links will display an error message.</p><div class="set-calendar-confirm-actions"><button type="button" class="btn-crm btn-crm--primary" data-calendar-confirm-turnoff>Turn off</button><button type="button" class="btn-crm btn-crm--outline" data-calendar-close>Cancel</button></div></div></dialog>
      <dialog class="set-modal set-calendar-add-dialog" id="calendar-exclusion-dialog"><form method="dialog"><div class="set-modal__head"><h2 class="set-modal__title">Add domain or email</h2><button type="button" class="icon-btn" data-calendar-close aria-label="Close">×</button></div><div class="field"><label class="field__label" for="calendar-exclusion-value">Domain or email address</label><input class="input" id="calendar-exclusion-value" name="exclusion" placeholder="example.com or name@example.com" required></div><div class="set-calendar-confirm-actions"><button type="button" class="btn-crm btn-crm--primary" data-calendar-save-exclusion>Add</button><button type="button" class="btn-crm btn-crm--outline" data-calendar-close>Cancel</button></div></form></dialog>
    </section>

    <!-- ============================================================ TASKS -->
    <section id="tab-tasks" class="crm-d-none" role="tabpanel">
      <p class="set-preferences-note">These preferences only apply to you.</p>
      <form class="set-tasks-form" data-settings-form novalidate>
        <section class="set-tasks-section"><h2 class="set-card__title">Defaults</h2><p class="set-calendar-description">Set preferences for task creation.</p>
          <div class="set-tasks-grid">
            <div class="field"><label class="field__label" for="t-due">Due date</label><div class="custom-select-wrapper" data-custom-select data-type="single"><select id="t-due" name="task_due" hidden><option>Today</option><option>Tomorrow</option><option selected>In 3 business days</option><option>In 1 week</option><option>In 2 weeks</option><option>In 1 month</option><option>In 3 months</option><option>In 6 months</option></select></div></div>
            <div class="field"><label class="field__label" for="t-time">Due time</label><div class="custom-select-wrapper" data-custom-select data-type="single" data-search="true"><select id="t-time" name="task_time" hidden><option selected>8:00 AM</option><option>8:30 AM</option><option>9:00 AM</option><option>9:30 AM</option><option>10:00 AM</option><option>10:30 AM</option><option>11:00 AM</option><option>11:30 AM</option><option>12:00 PM</option><option>12:30 PM</option><option>1:00 PM</option><option>1:30 PM</option><option>2:00 PM</option><option>2:30 PM</option><option>3:00 PM</option><option>3:30 PM</option><option>4:00 PM</option><option>4:30 PM</option><option>5:00 PM</option></select></div></div>
            <div class="field"><label class="field__label" for="t-reminder">Reminder</label><div class="custom-select-wrapper" data-custom-select data-type="single"><select id="t-reminder" name="task_reminder" hidden><option selected>No reminder</option><option>At task due time</option><option>30 minutes before</option><option>1 hour before</option><option>1 day before</option></select></div></div>
          </div>
        </section>
        <section class="set-tasks-section"><h2 class="set-card__title">Follow-up tasks</h2><p class="set-calendar-description">Set preferences for follow-up reminders.</p>
          <label class="check set-task-check"><input type="checkbox" name="followup_list_view" checked><span class="check__box" aria-hidden="true"></span><span>Get prompted to create a follow-up task every time you complete a task from a list view</span></label>
          <label class="check set-task-check"><input type="checkbox" name="followup_disqualify_lead" checked><span class="check__box" aria-hidden="true"></span><span>Get prompted to create a follow-up task every time you disqualify a lead</span></label>
        </section>
      </form>
    </section>

    <section id="tab-security" class="crm-d-none" role="tabpanel" aria-labelledby="security-tab">
      <div class="set-security-page">
        <p class="set-preferences-note">These preferences will only be applied to you.</p>
        <section class="set-security-section">
          <h2 class="set-security-title">Security</h2>
          <p class="set-security-subtitle">Set preferences related to login and your personal account security.</p>

          <div class="set-security-block">
            <h3>Email address</h3>
            <p class="set-security-value"><?php echo icon('mail', 'iconSize-16'); ?> <span><?php echo e($user['email']); ?></span></p>
            <button type="button" class="set-security-link" data-security-action="edit-email">Edit email address</button>
          </div>

          <div class="set-security-block">
            <h3>Password</h3>
            <button type="button" class="set-security-link" data-security-open="#security-reset-dialog">Reset password</button>
            <p class="set-security-meta">Last reset on October 26, 2026</p>
          </div>

          <div class="set-security-block">
            <h3>Deprecation</h3>
            <p class="set-security-description">If you don't use a password to log in for over 90 days, your password will be removed.</p>
            <table class="set-security-table set-security-table--small">
              <thead><tr><th>Status</th><th>Deprecation Date</th></tr></thead>
              <tbody><tr><td><span class="set-security-status-dot"></span>Ineligible</td><td>None</td></tr></tbody>
            </table>
          </div>

          <div class="set-security-block">
            <h3>Passkeys</h3>
            <div class="set-passkey-list" data-passkey-list>
              <div class="set-passkey" data-passkey-item>
                <span class="set-passkey-logo" aria-hidden="true">
                  <svg viewBox="0 0 32 32" role="img"><circle cx="10" cy="16" r="6" fill="#4285F4"/><circle cx="10" cy="16" r="2.8" fill="#fff"/><path d="M15 14h13v4h-3v3h-4v-3h-3z" fill="#34A853"/><path d="M19 14h4v4h-4z" fill="#FBBC04"/></svg>
                </span>
                <span class="set-passkey-details"><strong data-passkey-name>Google Password Manager</strong><small>Created on October 26, 2026</small></span>
                <span class="set-passkey-actions">
                  <button type="button" class="btn-crm btn-crm--outline btn-crm--sm" data-passkey-rename>Rename</button>
                  <button type="button" class="btn-crm btn-crm--danger btn-crm--sm" data-passkey-delete>Delete</button>
                </span>
              </div>
            </div>
            <button type="button" class="btn-crm btn-crm--outline btn-crm--sm set-security-add-passkey" data-security-action="add-passkey">Add another passkey</button>
            <p class="set-security-learn"><a href="#" data-security-learn>Learn more <?php echo icon('external', 'iconSize-14'); ?></a></p>
          </div>

          <div class="set-security-block set-security-block--twofa">
            <h3>Two-factor authentication (2FA)</h3>
            <p><button type="button" class="set-security-link" data-security-action="remove-security-app">Remove Security App</button><span class="set-security-meta">Primary method</span></p>
            <p><button type="button" class="set-security-link" data-security-action="setup-secondary-method">Set up secondary method</button><span class="set-security-meta">Secondary method</span></p>
            <p><button type="button" class="set-security-link" data-security-action="view-backup-codes">View backup codes</button><span class="set-security-meta">10 codes remaining</span></p>
          </div>
        </section>

        <section class="set-security-section set-security-section--sessions">
          <h2 class="set-security-title">Session Management</h2>
          <p class="set-security-subtitle">Manage your active and inactive sessions across devices.</p>
          <div class="set-security-table-wrap">
            <table class="set-security-table">
              <thead><tr><th>Device</th><th>Browser</th><th>IP Address <span class="set-security-info" title="Internet Protocol address">ⓘ</span></th><th>Last Active</th></tr></thead>
              <tbody data-security-sessions>
                <tr>
                  <td><span class="set-security-device">▣</span> Unknown device (Windows) <span class="set-security-current">Current</span><button type="button" class="set-security-session-logout" data-session-logout>Log out</button></td>
                  <td>Chrome 156.0.0.0</td><td>2401:4900:8927:faae:bd7d:b1f2:5cd7:eff0</td>
                  <td>October 27, 2026 12:49 PM<br>GMT+5:30 <small><i></i>a few seconds ago</small></td>
                </tr>
                <tr>
                  <td><span class="set-security-device">▣</span> Unknown device (Windows) <button type="button" class="set-security-session-logout" data-session-logout>Log out</button></td>
                  <td>Chrome 156.0.0.0</td><td>2401:4900:8927:f8d0:3092:13b0:8f67</td>
                  <td>October 27, 2026 7:49 AM<br>GMT+5:30 <small><i></i>5 hours ago</small></td>
                </tr>
                <tr>
                  <td><span class="set-security-device">▣</span> Mac (macOS) <button type="button" class="set-security-session-logout" data-session-logout>Log out</button></td>
                  <td>Chrome 155.0.0.0</td><td>2402:a00:408:afc5:ec93:73eb:816a:cf97</td>
                  <td>October 26, 2026 4:00 PM<br>GMT+5:30 <small><i></i>21 hours ago</small></td>
                </tr>
                <tr>
                  <td><span class="set-security-device">▣</span> Unknown device (Windows) <button type="button" class="set-security-session-logout" data-session-logout>Log out</button></td>
                  <td>Chrome 156.0.0.0</td><td>2401:4900:8927:faae:9d9d:1abc:9e4d:3e3e</td>
                  <td>October 26, 2026 2:04 PM<br>GMT+5:30 <small><i></i>a day ago</small></td>
                </tr>
              </tbody>
            </table>
          </div>
          <nav class="set-security-pagination" aria-label="Session pages"><button type="button" disabled>‹</button><span>Prev</span><strong>1</strong><span>Next</span><button type="button" disabled>›</button></nav>
          <div class="set-security-danger-block">
            <h3>Log Out of All Sessions</h3>
            <p>This will log you out of all devices and sessions, including this active one.</p>
            <button type="button" class="set-security-link" data-security-action="logout-all">Log Out of All Sessions</button>
          </div>
          <div class="set-security-danger-block">
            <h3>Remove from this account</h3>
            <p>This action will remove your user from this account. If you're part of other accounts, you'll still have access to them.</p>
            <button type="button" class="btn-crm btn-crm--danger" data-security-action="remove-account">Remove me from this account</button>
          </div>
          <div class="set-security-danger-block">
            <h3>Permanently Remove</h3>
            <button type="button" class="btn-crm btn-crm--danger" data-security-action="delete-account">Delete my user account</button>
          </div>
        </section>
      </div>
    </section>

    <section id="tab-automation" class="crm-d-none" role="tabpanel">
      <p class="set-preferences-note">These preferences only apply to you.</p>
      <div class="set-automation-page">
        <h2 class="set-security-title">Automation</h2>
        <p class="set-security-subtitle">Set preferences for automation tools.</p>
        <form class="set-automation-form" data-settings-form>
          <section class="set-automation-section">
            <h3>Workflows</h3>
            <label class="check set-automation-check">
              <input type="checkbox" name="workflow_minimap" value="1">
              <span class="check__box" aria-hidden="true"></span>
              <span class="set-automation-check-copy">
                <strong>Display the minimap by default</strong>
                <small>The minimap provides a zoomed-out overview of the entire flow canvas, making it easier to navigate large flows.</small>
              </span>
            </label>
            <div class="set-automation-zoom">
              <label class="field__label" for="workflow-default-zoom">Default zoom level</label>
              <p class="set-security-description" id="workflow-default-zoom-help">The default zoom level for the workflow canvas.</p>
              <div class="set-automation-zoom-input"><input class="input" id="workflow-default-zoom" name="workflow_default_zoom" type="text" value="100%" inputmode="decimal" autocomplete="off" spellcheck="false" aria-describedby="workflow-default-zoom-help"></div>
              <p class="field__error">Enter a zoom level between 25% and 200%.</p>
            </div>
          </section>
        </form>
      </div>
    </section>
  </div>
</div>

<!-- Change password -->
<dialog class="set-modal set-modal--drawer" id="password-dialog" aria-labelledby="pw-title">
  <form method="dialog" novalidate onsubmit="event.preventDefault(); if (CRM.validate(this)) { if (this.pw_new.value !== this.pw_confirm.value) { CRM.toast('New passwords do not match', 'danger'); return; } this.reset(); this.closest('dialog').close(); CRM.toast('Password updated', 'success'); }">
    <div class="set-modal__head">
      <h2 class="set-modal__title" id="pw-title">Change password</h2>
      <button type="button" class="icon-btn icon-btn--ghost" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button>
    </div>
    <div class="set-modal__body">
      <div class="field">
        <label class="field__label" for="pw-cur">Current password</label>
        <input class="input" id="pw-cur" name="pw_current" type="password" autocomplete="current-password" required>
        <p class="field__error">Enter your current password</p>
      </div>
      <div class="field">
        <label class="field__label" for="pw-new">New password</label>
        <input class="input" id="pw-new" name="pw_new" type="password" autocomplete="new-password" minlength="8" required>
        <p class="field__error">Use at least 8 characters</p>
      </div>
      <div class="field">
        <label class="field__label" for="pw-con">Confirm new password</label>
        <input class="input" id="pw-con" name="pw_confirm" type="password" autocomplete="new-password" required>
        <p class="field__error">Confirm your new password</p>
      </div>
    </div>
    <div class="set-modal__foot">
      <button type="button" class="btn-crm btn-crm--outline" data-dialog-close>Cancel</button>
      <button type="submit" class="btn-crm btn-crm--primary">Update password</button>
    </div>
  </form>
</dialog>


<!-- Security dialogs: isolated from the shared settings modal styles and scripts. -->

<dialog class="set-security-dialog set-security-verify-dialog" id="security-verify-dialog" aria-labelledby="security-verify-title">
  <div class="set-security-dialog-head"><h2 id="security-verify-title">Verify your identity</h2><button type="button" class="icon-btn icon-btn--ghost set-security-dialog-x" data-security-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button></div>
  <div class="set-security-dialog-body"><p class="set-security-verify-copy">You need to verify your identity before performing that action.</p><button type="button" class="btn-crm btn-crm--primary set-security-verify-choice" data-security-verify="passkey">♙ Verify with passkey</button><button type="button" class="btn-crm btn-crm--outline set-security-verify-choice" data-security-verify="2fa">Verify with 2FA</button></div>
</dialog>

<dialog class="set-security-dialog" id="security-reset-dialog" aria-labelledby="security-reset-title">
  <form method="dialog" data-security-reset-form>
    <header class="set-security-dialog-head"><h2 id="security-reset-title">Reset password</h2><button type="button" class="icon-btn icon-btn--ghost set-security-dialog-x" data-security-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button></header>
    <div class="set-security-dialog-body">
      <div class="field"><label class="field__label" for="security-current-password">Confirm current password</label><a href="#" class="set-security-link" data-security-action="forgot-password">Forgot my password</a><input class="input" id="security-current-password" name="current_password" type="password" autocomplete="current-password" required></div>
      <div class="field"><label class="field__label" for="security-new-password">New password</label><button type="button" class="set-security-link" data-security-show-password="#security-new-password">Show password</button><input class="input" id="security-new-password" name="new_password" type="password" autocomplete="new-password" required></div>
      <ul class="set-security-password-rules">
        <li data-password-rule="length"><span>✓</span>At least 12 characters long</li>
        <li data-password-rule="lower"><span>✓</span>One lowercase character</li>
        <li data-password-rule="upper"><span>✓</span>One uppercase character</li>
        <li data-password-rule="special"><span>✓</span>One number, symbol, or whitespace character</li>
      </ul>
    </div>
    <footer class="set-security-dialog-foot"><button type="submit" class="btn-crm btn-crm--primary" data-security-reset-submit disabled>Reset password</button><button type="button" class="btn-crm btn-crm--outline" data-security-close>Cancel</button></footer>
  </form>
</dialog>

<dialog class="set-security-dialog" id="security-action-dialog" aria-labelledby="security-action-title">
  <form method="dialog" data-security-action-form>
    <header class="set-security-dialog-head"><h2 id="security-action-title">Confirm action</h2><button type="button" class="icon-btn icon-btn--ghost set-security-dialog-x" data-security-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button></header>
    <div class="set-security-dialog-body">
      <p data-security-action-message></p>
      <div class="field" data-security-confirm-email-field hidden>
        <label class="field__label" for="security-confirm-email">Type your email address to confirm</label>
        <input class="input" id="security-confirm-email" name="confirm_email" type="email" autocomplete="off" placeholder="name@company.com">
      </div>
      <div class="field" data-security-rename-field hidden><label class="field__label" for="security-passkey-name">Passkey name</label><input class="input" id="security-passkey-name" name="passkey_name" maxlength="80"></div>
    </div>
    <footer class="set-security-dialog-foot"><button type="submit" class="btn-crm btn-crm--danger" data-security-action-confirm>Confirm</button><button type="button" class="btn-crm btn-crm--outline" data-security-close>Cancel</button></footer>
  </form>
</dialog>

<dialog class="set-security-dialog" id="security-email-dialog" aria-labelledby="security-email-title">
  <form method="dialog" data-security-email-form>
    <header class="set-security-dialog-head"><h2 id="security-email-title">Edit email address</h2><button type="button" class="icon-btn icon-btn--ghost set-security-dialog-x" data-security-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button></header>
    <div class="set-security-dialog-body"><p>Enter the new email address for your account. You may need to verify the address before it can be used.</p><div class="field"><label class="field__label" for="security-new-email">New email address</label><input class="input" id="security-new-email" name="new_email" type="email" required autocomplete="email"></div></div>
    <footer class="set-security-dialog-foot"><button type="submit" class="btn-crm btn-crm--primary">Continue</button><button type="button" class="btn-crm btn-crm--outline" data-security-close>Cancel</button></footer>
  </form>
</dialog>

<?php
$__provider = function ($name, $value, $checked) {
  $logos = array('google' => array('G', 'conn-logo--google', 'Google', 'Gmail or Google Workspace'), 'microsoft' => array('M', 'conn-logo--ms', 'Microsoft', 'Outlook or Office 365'), 'other' => array('@', 'conn-logo--other', 'Other (IMAP)', 'Any other email provider'));
  $l = $logos[$value];
  return '<label class="conn-option conn-option--radio"><input type="radio" name="' . $name . '" value="' . e($l[2]) . '"' . ($checked ? ' checked' : '') . '>'
       . '<span class="conn-logo ' . $l[1] . '">' . $l[0] . '</span><span><strong>' . e($l[2]) . '</strong><small>' . e($l[3]) . '</small></span></label>';
};

/* Connect personal email */
echo su_drawer('email-connect', 'Connect personal email',
  '<p class="field__help crm-mb-3">Pick your email provider. You sign in with that provider; the CRM never sees your password.</p>'
  . '<div class="field">' . $__provider('provider', 'google', true) . $__provider('provider', 'microsoft', false) . $__provider('provider', 'other', false) . '</div>'
  . su_field('Email address', '<input class="input" id="ec-email" name="email" type="email" required placeholder="you@example.com">', '', false, 'ec-email')
  . su_check('ec_auto', 'Turn on inbox automation (log and track emails)', true),
  'Connect', 'Email connected', 'id="email-connect-form"');

/* Connect calendar */
echo su_drawer('cal-connect', 'Connect calendar',
  '<p class="field__help crm-mb-3">Connect the calendar you use for meetings. Your free and busy times are used by the meetings scheduler.</p>'
  . '<div class="field">' . str_replace('Gmail or Google Workspace', 'Google Calendar', $__provider('cal_provider', 'google', true)) . str_replace('Outlook or Office 365', 'Outlook calendar', $__provider('cal_provider', 'microsoft', false)) . '</div>'
  . su_field('Calendar account', '<input class="input" id="cc-email" name="cal_email" type="email" required value="' . e($user['email']) . '">', '', false, 'cc-email')
  . '<div class="field"><p class="field__label">Sync options</p><div class="su-checks">'
  . su_check('cal_busy', 'Check my calendar for conflicts', true)
  . su_check('cal_add', 'Add CRM meetings to this calendar', true)
  . su_check('cal_log', 'Log meetings with contacts to the CRM', false)
  . '</div></div>',
  'Connect', 'Calendar connected', 'id="cal-connect-form" data-keep');

/* Add email alias drawer */
echo su_drawer('alias-dialog', 'Add email alias',
  '<p class="field__help crm-mb-3">Emails sent to or from this alias outside of the CRM will be logged to your account.</p>'
  . su_field('Email alias', '<input class="input" name="alias_email" type="email" required placeholder="alias@example.com">', '', false, 'alias-email'),
  'Add alias', 'Email alias added', 'id="alias-form"');

?>

<!-- Manage email signatures drawer -->
<dialog class="set-modal set-modal--drawer" id="sig-dialog" aria-labelledby="sig-title" data-default-sig="<?php echo e('<p>Best regards,<br>' . $user['name'] . '<br>Your Company</p>'); ?>">
  <form novalidate data-dialog-form data-keep data-success="Email signature saved" id="sig-form">
    <div class="set-modal__head">
      <h2 class="set-modal__title" id="sig-title">Manage email signatures</h2>
      <button type="button" class="icon-btn icon-btn--ghost" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button>
    </div>
    <div class="set-modal__body crm-gap-0">
      <div class="crm-d-flex crm-align-items-center crm-justify-content-between crm-mb-3">
        <label class="crm-fs-7 crm-fw-bold crm-text-dark crm-m-0">Signature</label>
        <div class="sig-mode-pills" role="radiogroup" aria-label="Signature format">
          <button type="button" class="sig-mode-btn is-active" data-sig-mode="simple" aria-checked="true" role="radio">Simple</button>
          <button type="button" class="sig-mode-btn" data-sig-mode="html" aria-checked="false" role="radio">HTML</button>
        </div>
      </div>

      <!-- Editor Container -->
      <div class="sig-editor-wrap crm-border crm-rounded-3 crm-overflow-hidden crm-d-flex crm-flex-column">
        <!-- Visual editable area (Simple mode) -->
        <div class="sig-editor-area" id="sig-editor-area" contenteditable="true" role="textbox" aria-multiline="true" data-placeholder="Start typing your signature..."></div>

        <!-- Raw HTML textarea (HTML mode) -->
        <textarea class="sig-html-area crm-p-3 crm-d-none" id="sig-html-area" rows="8" spellcheck="false" placeholder="<p>Enter HTML signature...</p>"></textarea>

        <!-- Bottom Toolbar (Simple mode) -->
        <div class="sig-toolbar crm-d-flex crm-align-items-center crm-gap-1 crm-px-2 crm-py-2 crm-border-top" id="sig-toolbar" role="toolbar" aria-label="Text formatting">
          <button type="button" class="sig-tool" data-sig-cmd="bold" title="Bold (Ctrl+B)" aria-label="Bold">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 5h6a3.5 3.5 0 0 1 0 7H7zM7 12h7a3.5 3.5 0 0 1 0 7H7z"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-cmd="italic" title="Italic (Ctrl+I)" aria-label="Italic">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 4h-9M14 20H5M15 4 9 20"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-cmd="underline" title="Underline (Ctrl+U)" aria-label="Underline">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4M4 21h16"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-cmd="removeFormat" title="Clear formatting" aria-label="Clear formatting">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 7V5h11v2M9.5 5 7 19M4 19h7M15 15l6 6M21 15l-6 6"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-cmd="insertUnorderedList" title="Bulleted list" aria-label="Bulleted list">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 6h11M9 12h11M9 18h11"/><circle cx="4.5" cy="6" r="1" fill="currentColor"/><circle cx="4.5" cy="12" r="1" fill="currentColor"/><circle cx="4.5" cy="18" r="1" fill="currentColor"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-cmd="insertOrderedList" title="Numbered list" aria-label="Numbered list">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 6h10M10 12h10M10 18h10M4 5h1v4M4 9h2M4 14h2l-2 3h2"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-action="image" title="Insert image" aria-label="Insert image">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="8.5" cy="9.5" r="1.5"/><path d="m21 16-5-5-9 9"/></svg>
          </button>
          <button type="button" class="sig-tool" data-sig-action="link" title="Insert link (Ctrl+K)" aria-label="Insert link">
            <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/><path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></svg>
          </button>
        </div>
      </div>

      <textarea name="email_signature" id="sig-hidden-input" hidden></textarea>

      <!-- Add new signature upgrade link -->
      <div class="crm-mt-3">
        <a href="#upgrade-signatures" class="crm-d-inline-flex crm-align-items-center crm-gap-1 crm-fs-7 crm-fw-semibold" style="color: var(--brand); text-decoration: none;" id="btn-add-sig-upgrade">
          <span>Add new signature</span>
          <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="5" y="10" width="14" height="11" rx="2"/><path d="M8 10V7a4 4 0 0 1 8 0v3"/></svg>
        </a>
      </div>
    </div>
    <div class="set-modal__foot crm-d-flex crm-align-items-center crm-gap-2" style="flex-direction: row; justify-content: flex-start;">
      <button type="submit" class="btn-crm btn-crm--primary">Save</button>
      <button type="button" class="btn-crm btn-crm--outline" data-dialog-close>Cancel</button>
    </div>
  </form>
</dialog>

<?php
/* Edit unsubscribe link drawer */
echo su_drawer('unsub-dialog', 'Text for unsubscribe link',
  '<p class="crm-m-0 crm-fs-7 crm-text-dark crm-lh-base crm-mb-4">This unsubscribe link will be shown below your email signature in all CRM and sequence emails.</p>'
  . '<div class="crm-d-flex crm-flex-column crm-gap-3">'
  .   '<label class="set-radio">'
  .     '<input type="radio" name="unsub_choice" value="Is this email not relevant to you? Click here" checked>'
  .     '<span class="set-radio__circle" aria-hidden="true"></span>'
  .     '<span>Is this email not relevant to you? Click <strong class="crm-text-primary">here</strong></span>'
  .   '</label>'
  .   '<label class="set-radio">'
  .     '<input type="radio" name="unsub_choice" value="To stop receiving these emails, click here">'
  .     '<span class="set-radio__circle" aria-hidden="true"></span>'
  .     '<span>To stop receiving these emails, click <strong class="crm-text-primary">here</strong></span>'
  .   '</label>'
  .   '<label class="set-radio">'
  .     '<input type="radio" name="unsub_choice" value="Prefer fewer emails from me? Click here">'
  .     '<span class="set-radio__circle" aria-hidden="true"></span>'
  .     '<span>Prefer fewer emails from me? Click <strong class="crm-text-primary">here</strong></span>'
  .   '</label>'
  . '</div>',
  'Save', 'Unsubscribe link updated', 'id="unsub-form" data-keep');

/* Never log drawer */
echo su_drawer('neverlog-dialog', 'Add emails or domains to Never Log',
  '<p class="field__help crm-mb-3">Specify domains (e.g. <code>example.com</code>) or exact email addresses to block from automatic logging.</p>'
  . su_field('Domains or emails', '<textarea class="input" name="never_log_items" rows="4" required placeholder="competitor.com&#10;personal@domain.com" id="nl-items"></textarea>', 'Separate multiple entries with commas or newlines.', false, 'nl-items'),
  'Add to list', 'Added to Never Log list', 'id="neverlog-form"');

?>

<!-- Additional BCC address drawer -->
<dialog class="set-modal set-modal--drawer" id="bcc-dialog" aria-labelledby="bcc-title">
  <form novalidate data-dialog-form data-keep data-success="BCC settings saved" id="bcc-form">
    <div class="set-modal__head">
      <h2 class="set-modal__title" id="bcc-title">Additional BCC address</h2>
      <button type="button" class="icon-btn icon-btn--ghost" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button>
    </div>
    <div class="set-modal__body">
      <p class="crm-m-0 crm-fs-7 crm-text-dark crm-lh-base crm-mb-3">Log emails you send to an external CRM in addition to your CRM. Only works for emails sent using a sales extension.</p>
      <div class="crm-p-3 crm-rounded-3 crm-bg-warning-subtle crm-border crm-border-warning-subtle crm-fs-7 crm-text-dark crm-lh-base crm-mb-4">
        This feature can't be used for BCC addresses of other CRM accounts
      </div>
      <div class="crm-d-flex crm-gap-2 crm-mb-3">
        <input class="input crm-flex-grow-1" id="bcc-input" type="email" placeholder="Enter a BCC address">
        <button type="button" class="btn-crm btn-crm--outline crm-h-100" id="btn-add-bcc" disabled>Add</button>
      </div>
      <div id="bcc-list-section">
        <p class="crm-fs-7 crm-fw-bold crm-text-dark crm-mb-2">BCC Addresses:</p>
        <div id="bcc-address-list" class="crm-d-flex crm-flex-column crm-gap-2">
          <div class="crm-d-flex crm-align-items-center crm-gap-2" data-bcc-item="44357896@bcc.CRM.com">
            <span class="crm-fs-7 crm-text-dark">44357896@bcc.CRM.com</span>
            <button type="button" class="icon-btn w-32 h-32 crm-rounded-circle" data-remove-bcc="44357896@bcc.CRM.com" aria-label="Delete BCC address 44357896@bcc.CRM.com">
              <?php echo icon('trash', 'iconSize-16'); ?>
            </button>
          </div>
        </div>
      </div>
    </div>
    <div class="set-modal__foot crm-d-flex crm-align-items-center crm-gap-2" style="flex-direction: row; justify-content: flex-start;">
      <button type="submit" class="btn-crm btn-crm--primary">Save</button>
      <button type="button" class="btn-crm btn-crm--outline" data-dialog-close>Cancel</button>
      <button type="button" class="btn-crm btn-crm--ghost crm-text-dark crm-fw-semibold" id="btn-bcc-reset">Reset</button>
    </div>
  </form>
</dialog>

<!-- Blocked IP addresses drawer -->
<dialog class="set-modal set-modal--drawer" id="blocked-ips-dialog" aria-labelledby="blocked-ips-title">
  <form novalidate data-dialog-form data-keep data-success="Blocked IP addresses saved" id="blocked-ips-form">
    <div class="set-modal__head">
      <h2 class="set-modal__title" id="blocked-ips-title">Blocked IP Addresses</h2>
      <button type="button" class="icon-btn icon-btn--ghost" data-dialog-close aria-label="Close"><?php echo icon('x', 'iconSize-20'); ?></button>
    </div>
    <div class="set-modal__body">
      <p class="crm-m-0 crm-fs-7 crm-text-dark crm-lh-base crm-mb-3">Don't track email opens or clicks from specific IP addresses. Your current IP address is: 207.244.71.82</p>
      
      <div class="crm-d-flex crm-gap-2 crm-mb-3">
        <input class="input crm-flex-grow-1" id="ip-input" type="text" placeholder="Enter an IP address (e.g. 12.324.245.23)">
        <button type="button" class="btn-crm btn-crm--outline crm-h-100" id="btn-add-ip" disabled>Add</button>
      </div>

      <div id="blocked-ips-list">
        <p class="crm-fs-7 crm-text-dark crm-m-0"><strong>Blocked IPs:</strong> none</p>
      </div>
    </div>
    <div class="set-modal__foot crm-d-flex crm-align-items-center crm-gap-2" style="flex-direction: row; justify-content: flex-start;">
      <button type="submit" class="btn-crm btn-crm--primary">Save</button>
      <button type="button" class="btn-crm btn-crm--outline" data-dialog-close>Cancel</button>
    </div>
  </form>
</dialog>

<!-- Sign out everywhere (confirmation, centred) -->
<dialog class="set-modal" id="signout-dialog" aria-labelledby="so-title">
  <form novalidate data-dialog-form data-success="Signed out of 3 other sessions">
    <?php echo su_dialog_head('Sign out everywhere?', 'so-title'); ?>
    <div class="set-modal__body">
      <p>You will stay signed in here. These sessions will be signed out:</p>
      <ul class="crm-mt-2 field__help">
        <li>Chrome on Windows · Pune · 2 hours ago</li>
        <li>Safari on iPhone · Mumbai · Yesterday</li>
        <li>CRM mobile app on Android · 3 days ago</li>
      </ul>
    </div>
    <div class="set-modal__foot">
      <button type="button" class="btn-crm btn-crm--outline" data-dialog-close>Cancel</button>
      <button type="submit" class="btn-crm btn-crm--primary">Sign out everywhere</button>
    </div>
  </form>
</dialog>

<script type="module">
  const $ = (s, c) => (c || document).querySelector(s);
  const $$ = (s, c) => Array.from((c || document).querySelectorAll(s));
  const esc = v => String(v).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));

  /* personal email: add a row to the connected list */
  const ef = $('#email-connect-form');
  if (ef) {
    ef.addEventListener('saved', e => {
      const d = e.detail, auto = d.get('ec_auto');
      $('[data-email-list]').insertAdjacentHTML('beforeend', '<div class="connect-row crm-mt-3"><span class="connect-row__icon"><?php echo addslashes(icon('mail')); ?></span>'
        + '<div class="connect-row__body"><p class="crm-fw-semibold">' + esc(d.get('email')) + '</p><p class="field__help">' + esc(d.get('provider')) + ' &middot; inbox automation ' + (auto ? 'on' : 'off') + '</p></div>'
        + '<span class="badge badge--success">Connected</span><button type="button" class="btn-crm btn-crm--outline btn-crm--sm su-danger" data-email-off>Disconnect</button></div>');
      ef.dataset.success = d.get('email') + ' connected';
    });
  }

  document.addEventListener('click', e => {
    const off = e.target.closest('[data-email-off]');
    if (off) { off.closest('.connect-row').remove(); CRM.toast('Email disconnected', 'info'); }
  });

  /* Unsubscribe toggle enables edit button */
  const chkUnsub = $('#chk-unsubscribe');
  const btnUnsub = $('#btn-unsubscribe-edit');
  if (chkUnsub && btnUnsub) {
    chkUnsub.addEventListener('change', () => {
      btnUnsub.disabled = !chkUnsub.checked;
    });
  }

  /* Unsubscribe modal choice persistence */
  const unsubForm = $('#unsub-form');
  const unsubKey = 'crm_unsub_choice';
  if (unsubForm) {
    const savedChoice = localStorage.getItem(unsubKey);
    if (savedChoice) {
      const radio = unsubForm.querySelector(`input[name="unsub_choice"][value="${savedChoice}"]`);
      if (radio) radio.checked = true;
    }
    unsubForm.addEventListener('saved', e => {
      const val = e.detail.get('unsub_choice');
      if (val) localStorage.setItem(unsubKey, val);
    });
  }

  /* Never log add item */
  const nlf = $('#neverlog-form');
  const nlRows = $('#never-log-rows');
  if (nlf && nlRows) {
    nlf.addEventListener('saved', e => {
      const items = (e.detail.get('never_log_items') || '').split(/[\n,]+/).map(s => s.trim()).filter(Boolean);
      items.forEach(item => {
        nlRows.insertAdjacentHTML('beforeend',
          '<tr data-row><td class="crm-fw-semibold">' + esc(item) + '</td>' +
          '<td class="crm-text-muted crm-fst-italic crm-fs-7">Added by you</td>' +
          '<td class="crm-text-end"><span class="badge badge--neutral">You</span></td></tr>'
        );
      });
    });
  }

  /* Email Alias handling */
  const aliasForm = $('#alias-form');
  const aliasSection = $('#email-alias-section');
  const aliasList = $('#email-alias-list');
  const aliasStorageKey = 'crm_email_aliases';

  const getAliases = () => {
    try {
      const raw = localStorage.getItem(aliasStorageKey);
      if (raw === null) return ['test@gmail.com'];
      return JSON.parse(raw);
    } catch (_) {
      return ['test@gmail.com'];
    }
  };

  const saveAliases = list => {
    try {
      localStorage.setItem(aliasStorageKey, JSON.stringify(list));
    } catch (_) {}
  };

  const renderAliases = () => {
    if (!aliasSection || !aliasList) return;
    const aliases = getAliases();
    if (!aliases.length) {
      aliasSection.hidden = true;
      aliasList.innerHTML = '';
      return;
    }
    aliasSection.hidden = false;
    aliasList.innerHTML = aliases.map(email => `
      <div class="crm-d-flex crm-align-items-center crm-gap-2" data-alias-item="${esc(email)}">
        <span class="crm-fs-7 crm-text-dark">${esc(email)}</span>
        <button type="button" class="icon-btn w-32 h-32 crm-rounded-circle" data-remove-alias="${esc(email)}" aria-label="Delete alias ${esc(email)}">
          <svg class="icon iconSize-16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6"/></svg>
        </button>
      </div>
    `).join('');
  };

  if (aliasForm) {
    aliasForm.addEventListener('saved', e => {
      const email = (e.detail.get('alias_email') || '').trim();
      if (!email) return;
      const current = getAliases();
      if (!current.includes(email)) {
        current.push(email);
        saveAliases(current);
      }
      renderAliases();
    });
  }

  document.addEventListener('click', e => {
    const btn = e.target.closest('[data-remove-alias]');
    if (!btn) return;
    const email = btn.dataset.removeAlias;
    const current = getAliases().filter(a => a !== email);
    saveAliases(current);
    renderAliases();
    CRM.toast('Email alias removed', 'info');
  });

  renderAliases();

  /* Additional BCC addresses handling */
  const bccForm = $('#bcc-form');
  const bccInput = $('#bcc-input');
  const btnAddBcc = $('#btn-add-bcc');
  const bccList = $('#bcc-address-list');
  const btnBccReset = $('#btn-bcc-reset');
  const bccDialog = $('#bcc-dialog');
  const bccStorageKey = 'crm_bcc_addresses';
  const defaultBcc = ['44357896@bcc.CRM.com'];

  const getBccList = () => {
    try {
      const raw = localStorage.getItem(bccStorageKey);
      if (raw === null) return [...defaultBcc];
      return JSON.parse(raw);
    } catch (_) {
      return [...defaultBcc];
    }
  };

  const saveBccList = list => {
    try {
      localStorage.setItem(bccStorageKey, JSON.stringify(list));
    } catch (_) {}
  };

  let stagedBcc = getBccList();

  const updateAddBtn = () => {
    if (!btnAddBcc || !bccInput) return;
    btnAddBcc.disabled = !bccInput.value.trim();
  };

  const renderBcc = () => {
    if (!bccList) return;
    if (!stagedBcc.length) {
      bccList.innerHTML = '<p class="crm-fs-7 crm-text-muted crm-fst-italic crm-m-0">No BCC addresses added.</p>';
      return;
    }
    bccList.innerHTML = stagedBcc.map(email => `
      <div class="crm-d-flex crm-align-items-center crm-gap-2" data-bcc-item="${esc(email)}">
        <span class="crm-fs-7 crm-text-dark">${esc(email)}</span>
        <button type="button" class="icon-btn w-32 h-32 crm-rounded-circle" data-remove-bcc="${esc(email)}" aria-label="Delete BCC address ${esc(email)}">
          <svg class="icon iconSize-16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M10 11v6M14 11v6"/></svg>
        </button>
      </div>
    `).join('');
  };

  const addBccItem = () => {
    if (!bccInput) return;
    const email = bccInput.value.trim();
    if (!email) return;
    if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
      CRM.toast('Please enter a valid email address', 'danger');
      return;
    }
    if (stagedBcc.includes(email)) {
      CRM.toast('Address already added', 'warning');
      return;
    }
    stagedBcc.push(email);
    bccInput.value = '';
    updateAddBtn();
    renderBcc();
  };

  if (btnAddBcc) {
    btnAddBcc.addEventListener('click', e => {
      e.preventDefault();
      addBccItem();
    });
  }

  if (bccInput) {
    bccInput.addEventListener('input', updateAddBtn);
    bccInput.addEventListener('keydown', e => {
      if (e.key === 'Enter') {
        e.preventDefault();
        addBccItem();
      }
    });
  }

  if (btnBccReset) {
    btnBccReset.addEventListener('click', e => {
      e.preventDefault();
      stagedBcc = [...defaultBcc];
      renderBcc();
      CRM.toast('Reset to default BCC address', 'info');
    });
  }

  document.addEventListener('click', e => {
    const btn = e.target.closest('[data-remove-bcc]');
    if (!btn) return;
    const email = btn.dataset.removeBcc;
    stagedBcc = stagedBcc.filter(b => b !== email);
    renderBcc();
  });

  if (bccForm) {
    bccForm.addEventListener('saved', () => {
      if (bccInput && bccInput.value.trim() && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(bccInput.value.trim())) {
        const val = bccInput.value.trim();
        if (!stagedBcc.includes(val)) stagedBcc.push(val);
        bccInput.value = '';
        updateAddBtn();
      }
      saveBccList(stagedBcc);
    });
  }

  if (bccDialog) {
    bccDialog.addEventListener('close', () => {
      stagedBcc = getBccList();
      renderBcc();
      if (bccInput) {
        bccInput.value = '';
        updateAddBtn();
      }
    });
  }

  updateAddBtn();
  renderBcc();
  const notifBtn = $('[data-enable-notifications]');
  if (notifBtn) {
    notifBtn.addEventListener('click', () => {
      const offState = $('[data-notifications-off]');
      const onState = $('[data-notifications-on]');
      if (offState) offState.hidden = true;
      if (onState) onState.hidden = false;
      CRM.toast('Browser notifications enabled', 'success');
    });
  }

  /* calendar: show the connected calendar in the row */
  const cf = $('#cal-connect-form'), row = $('[data-cal-row]');
  const show = on => {
    ['[data-cal-badge]', '[data-cal-manage]', '[data-cal-off]'].forEach(s => { $(s, row).hidden = !on; });
    $('[data-cal-on]', row).hidden = on;
  };
  if (cf && row) {
    cf.addEventListener('saved', e => {
      const d = e.detail, opts = [d.get('cal_busy') && 'checks conflicts', d.get('cal_add') && 'adds meetings', d.get('cal_log') && 'logs meetings'].filter(Boolean);
      $('[data-cal-title]', row).textContent = d.get('cal_provider') + ' Calendar · ' + d.get('cal_email');
      $('[data-cal-sub]', row).textContent = 'Syncing' + (opts.length ? ' · ' + opts.join(', ') : '');
      $('#cal-connect-title').textContent = 'Calendar settings';
      $('button[type="submit"]', cf).textContent = 'Save';
      cf.dataset.success = row.dataset.connected ? 'Calendar settings saved' : 'Calendar connected';
      row.dataset.connected = '1';
      show(true);
    });
    $('[data-cal-off]', row).addEventListener('click', () => {
      delete row.dataset.connected;
      $('[data-cal-title]', row).textContent = 'No calendar connected';
      $('[data-cal-sub]', row).textContent = 'Google Calendar or Microsoft Outlook';
      $('#cal-connect-title').textContent = 'Connect calendar';
      $('button[type="submit"]', cf).textContent = 'Connect';
      show(false);
      CRM.toast('Calendar disconnected', 'info');
    });
  }
</script>

<!-- Save bar (shows when a settings form changes) -->
<div class="save-bar" data-save-bar role="region" aria-label="Unsaved changes">
  <span class="save-bar__text">You have unsaved changes</span>
  <button type="button" class="btn-crm btn-crm--outline" data-cancel>Cancel</button>
  <button type="button" class="btn-crm btn-crm--primary" data-save><span class="btn-crm__spinner" aria-hidden="true"></span>Save</button>
</div>

<script>
(function () {
  /* Tab switching: in-page toggle + keeps URL hash and responsive More tabs synced */
  var tabsNav = document.querySelector('[data-os-tabs]');
  if (!tabsNav) return;

  var tabPanels = {
    profile: document.getElementById('tab-profile'),
    email: document.getElementById('tab-email'),
    calling: document.getElementById('tab-calling'),
    calendar: document.getElementById('tab-calendar'),
    tasks: document.getElementById('tab-tasks'),
    security: document.getElementById('tab-security'),
    automation: document.getElementById('tab-automation')
  };

  function activateTab(targetTab, updateHistory) {
    if (!tabPanels[targetTab]) targetTab = 'profile';

    // Toggle panels
    Object.keys(tabPanels).forEach(function (key) {
      var panel = tabPanels[key];
      if (panel) {
        panel.classList.toggle('crm-d-none', key !== targetTab);
      }
    });

    // Update tab active states
    var allTabs = tabsNav.querySelectorAll('[data-os-tab]');
    allTabs.forEach(function (t) {
      var on = t.getAttribute('data-os-tab') === targetTab;
      t.classList.toggle('is-active', on);
      if (on) {
        t.setAttribute('aria-current', 'page');
      } else {
        t.removeAttribute('aria-current');
      }
    });

    if (updateHistory) {
      try {
        history.replaceState(null, '', '#tab-' + targetTab);
      } catch (err) {}
    }

    // Trigger fitTabs so overflow into More is recalculated
    window.dispatchEvent(new Event('resize'));
  }

  // Handle tab clicks (both main bar and More menu)
  document.addEventListener('click', function (e) {
    var tabLink = e.target.closest('[data-os-tabs] [data-os-tab]');
    if (!tabLink) return;
    var targetTab = tabLink.getAttribute('data-os-tab');
    if (!targetTab) return;

    e.preventDefault();
    activateTab(targetTab, true);
  });

  // Handle initial hash or query parameter
  function checkInitialTab() {
    var hash = location.hash ? location.hash.replace('#tab-', '').replace('#', '') : '';
    var param = '';
    try {
      param = new URLSearchParams(location.search).get('tab') || '';
    } catch (e) {}
    var initial = hash || param;
    if (initial && tabPanels[initial]) {
      activateTab(initial, false);
    }
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', checkInitialTab);
  } else {
    checkInitialTab();
  }

  window.addEventListener('hashchange', function () {
    var hash = location.hash ? location.hash.replace('#tab-', '').replace('#', '') : '';
    if (hash && tabPanels[hash]) {
      activateTab(hash, false);
    }
  });
})();
</script>

<?php include __DIR__ . '/includes/footer.php'; ?>
