// Start-new-conversation modal. Triggered by the "Start New" button in the
// conversation list header.
//
// One field does the work: type a name to search contacts and teammates, or
// type a number to reach someone who is not a contact yet. Both resolve to the
// same recipient, and the footer offers the only two things you can do with
// one — message or call. The footer does not exist until there is a recipient,
// so the modal never shows an action that cannot fire.
//
// The body is a single slot with five states:
//
//   empty       the hint — what this field accepts
//   too short   search waits for two characters rather than matching on one
//   searching   skeleton rows, so the list does not flash in and out
//   results     contacts, then teammates. A typed number leads the list as
//               "not in contacts", because that is the one row search cannot
//               confirm and the one the user most needs offered
//   keypad      the dialpad, replacing the list — you are dialling, not
//               searching, so a stale result list underneath would only lie
//
// Keyboard: up/down move the cursor, Enter messages, Cmd/Ctrl+Enter calls, Esc
// closes — the audio popover first when that is open, so one Esc never does two
// things. With the keypad open, physical digits light the on-screen key, so the
// two ways in don't feel like two different modals.
//
// The From line is a text link rather than a boxed select: it is set correctly
// almost every time, and a full-width field at the top of the modal reads as
// the first thing to fill in when the recipient is.
const StartNewModal = ({ open, onClose, onMessage, onCall }) => {
  const lines = window.PHONE_LINES || [];

  // Search waits for two characters — one matches most of the book, so the
  // first keystroke would render a list that is never the answer.
  const MIN_Q = 2;
  const SEARCH_MS = 280;

  // Contacts come from the inbox and teammates from the agent list — the same
  // records the rest of Conversations shows, so a name picked here looks the
  // same once the thread opens.
  const contacts = (window.THREADS || []).map((t) => ({
    name: t.name, sub: t.phone, avatar: t.avatar,
    tag: (t.tags && t.tags[0]) || null
  }));
  const team = (window.AGENTS || []).map((a) => ({
    name: a.name, sub: a.role, avatar: a.initials, team: true
  }));

  const [lineIdx, setLineIdx] = useState(0);
  const [linePop, setLinePop] = useState(false);
  const [q, setQ] = useState("");
  const [sel, setSel] = useState(null);
  const [cur, setCur] = useState(0);
  const [pad, setPad] = useState(false);
  const [loading, setLoading] = useState(false);
  const [settings, setSettings] = useState(false);
  const [audio, setAudio] = useState({ mic: 0, spk: 0, ring: 0 });
  const [flash, setFlash] = useState(null);
  const inputRef = useRef(null);

  // Reset on each open — a half-typed number from last time is never what the
  // next conversation starts from.
  useEffect(() => {
    if (!open) return;
    setLineIdx(0); setLinePop(false); setQ(""); setSel(null); setCur(0);
    setPad(false); setLoading(false); setSettings(false); setFlash(null);
  }, [open]);

  // The skeleton is on a timer rather than tied to real work: it exists so the
  // list settles once instead of rewriting itself on every keystroke. Whether
  // it is showing is set as the query changes, not in an effect afterwards —
  // an effect renders one frame of results first and the list visibly flickers.
  useEffect(() => {
    if (!loading) return;
    const t = setTimeout(() => setLoading(false), SEARCH_MS);
    return () => clearTimeout(t);
  }, [loading, q]);

  useEffect(() => {
    if (open && !sel && inputRef.current) inputRef.current.focus();
  }, [open, sel, pad]);

  const digits = (v) => String(v || "").replace(/\D/g, "");
  const isNum = (v) => /[0-9]/.test(v) && digits(v).length >= 3;

  // Name match on the substring, number match on digits only, so "(415) 555"
  // and "415555" are the same query.
  const match = (list, s) => {
    const k = s.trim().toLowerCase();
    const d = digits(k);
    return list.filter((p) =>
      p.name.toLowerCase().includes(k) || (!!d && digits(p.sub).includes(d)));
  };

  const query = q.trim();
  const items = pad || sel || loading || query.length < MIN_Q ? [] : [
    ...(isNum(query) ? [{ raw: true, name: query, sub: "Not in contacts — start a new thread" }] : []),
    ...match(contacts, query),
    ...match(team, query)
  ];

  // What Enter would act on: an explicit pick, else the number on the keypad,
  // else whatever the cursor is sitting on.
  const recipient = sel ? sel :
    pad ? isNum(q) ? { raw: true, name: q, sub: q } : null :
    items[cur] || null;

  const line = lines[lineIdx] || null;

  const initials = (n) =>
    String(n).replace(/\(.*\)/, "").trim().split(/\s+/).slice(0, 2)
      .map((w) => w[0]).join("").toUpperCase();

  const commit = (mode) => {
    if (!recipient) return;
    const payload = { to: recipient.name, line };
    if (mode === "call") onCall(payload); else onMessage(payload);
  };

  const setQuery = (v) => {
    setQ(v); setCur(0); setSel(null);
    setLoading(!pad && v.trim().length >= MIN_Q);
  };

  // A physical digit lights the matching on-screen key. The character still
  // reaches the input — this only makes the keypad look connected to the
  // keyboard rather than decorative.
  const flashKey = (k) => {
    setFlash(k);
    setTimeout(() => setFlash((f) => (f === k ? null : f)), 160);
  };

  // Escape has to clear the popovers before it closes the modal, or a stray
  // Esc loses everything typed just to dismiss a menu.
  useEffect(() => {
    if (!open) return;
    const onKey = (e) => {
      if (e.key === "Escape") {
        if (settings) { setSettings(false); return; }
        if (linePop) { setLinePop(false); return; }
        onClose();
        return;
      }
      if (pad && /^[0-9*#]$/.test(e.key)) flashKey(e.key);
      const n = items.length;
      if (e.key === "ArrowDown" && n) { e.preventDefault(); setCur((c) => (c + 1) % n); }
      if (e.key === "ArrowUp" && n) { e.preventDefault(); setCur((c) => (c - 1 + n) % n); }
      if (e.key === "Enter" && recipient) {
        e.preventDefault();
        commit(e.metaKey || e.ctrlKey ? "call" : "message");
      }
    };
    document.addEventListener("keydown", onKey);
    return () => document.removeEventListener("keydown", onKey);
  }, [open, settings, linePop, pad, items.length, recipient, cur, lineIdx]);

  // Any click outside an open popover closes it — including a click on the
  // modal's own body, which is where people aim when they mean "never mind".
  useEffect(() => {
    if (!open || (!linePop && !settings)) return;
    const onDown = (e) => {
      if (linePop && !e.target.closest("[data-snm-line]")) setLinePop(false);
      if (settings && !e.target.closest("[data-snm-audio]")) setSettings(false);
    };
    document.addEventListener("mousedown", onDown);
    return () => document.removeEventListener("mousedown", onDown);
  }, [open, linePop, settings]);

  if (!open) return null;

  const C = {
    brand: "#004CE6", brandHover: "#003BB3", brandSoft: "#EFF8FF", brandLine: "#B2DDFF",
    ink: "#101828", ink2: "#344054", muted: "#667085", faint: "#98A2B3",
    line: "#E4E7EC", line2: "#D0D5DD", soft: "#F2F4F7", canvas: "#F9FAFB",
    rawBg: "#FFFAEB", rawFg: "#B54708"
  };

  const KEYS = [
  ["1", ""], ["2", "ABC"], ["3", "DEF"],
  ["4", "GHI"], ["5", "JKL"], ["6", "MNO"],
  ["7", "PQRS"], ["8", "TUV"], ["9", "WXYZ"],
  ["*", ""], ["0", "+"], ["#", ""]];


  const DEVICES = {
    mic: ["Default — MacBook Pro Microphone (Built-in)", "Jabra Evolve2 65", "AirPods Pro", "Studio Display Microphone"],
    spk: ["Default — MacBook Pro Speakers (Built-in)", "Jabra Evolve2 65", "AirPods Pro", "Studio Display Speakers"],
    ring: ["Default — MacBook Pro Speakers (Built-in)", "Jabra Evolve2 65", "AirPods Pro", "Studio Display Speakers"]
  };

  const kbd = {
    fontFamily: "inherit", fontSize: 11, border: `1px solid ${C.line}`,
    borderBottomWidth: 2, borderRadius: 5, padding: "1px 5px",
    background: "#FFFFFF", color: C.muted
  };

  const toolBtn = (on) => ({
    width: 32, height: 32, borderRadius: 8, flex: "0 0 32px",
    border: `1px solid ${on ? C.brandLine : C.line}`,
    background: on ? C.brandSoft : "#FFFFFF",
    color: on ? C.brand : C.muted,
    display: "grid", placeItems: "center", cursor: "pointer", padding: 0
  });

  const hint = (text) =>
  <div style={{ padding: "0 20px 18px", fontSize: 12.5, color: C.faint, lineHeight: 1.5 }}>{text}</div>;

  const sep = <div style={{ height: 1, background: C.line }} />;

  const Avatar = ({ children, tone, size = 30 }) =>
  <span style={{
    width: size, height: size, flex: `0 0 ${size}px`, borderRadius: "50%",
    display: "grid", placeItems: "center", fontSize: size > 24 ? 10.5 : 9, fontWeight: 600,
    background: tone === "raw" ? C.rawBg : C.brandSoft,
    color: tone === "raw" ? C.rawFg : "#175CD3"
  }}>{children}</span>;

  const PersonRow = ({ p, i }) => {
    const on = i === cur;
    const tagStyle = p.tag ? tagStyleFor(p.tag) : null;
    return (
      <button
        className="snm-person"
        onClick={() => { setSel(p); setCur(0); }}
        aria-selected={on}
        style={{
          width: "100%", display: "flex", alignItems: "center", gap: 11,
          background: on ? C.brandSoft : "transparent", border: "none",
          padding: "8px 8px", borderRadius: 9, textAlign: "left",
          cursor: "pointer", fontFamily: "inherit"
        }}>
        <Avatar tone={p.raw ? "raw" : ""}>{p.raw ? "#" : p.avatar || initials(p.name)}</Avatar>
        <span style={{ minWidth: 0 }}>
          <span style={{
            display: "block", fontSize: 13.5, fontWeight: 500, color: C.ink,
            whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis"
          }}>{p.name}</span>
          <span style={{ display: "block", fontSize: 12, color: C.muted }}>{p.sub}</span>
        </span>
        <span style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 6, flexShrink: 0 }}>
          {on ?
          <span style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 11.5, color: C.faint }}>
              <span style={kbd}>↵</span> message
            </span> :
          p.team ?
          <span style={{
            fontSize: 11, fontWeight: 500, borderRadius: 6, padding: "2px 8px",
            border: `1px solid ${C.line2}`, color: C.ink2, background: "#FFFFFF"
          }}>Teammate</span> :
          tagStyle ?
          <span style={{
            fontSize: 11, fontWeight: 500, borderRadius: 6, padding: "2px 8px",
            border: `1px solid ${tagStyle.bd}`, color: tagStyle.fg, background: "#FFFFFF"
          }}>{p.tag}</span> :
          null}
        </span>
      </button>);

  };

  return (
    <div
      className="snm-scrim"
      onMouseDown={(e) => {if (e.target === e.currentTarget) onClose();}}
      style={{
        position: "fixed", inset: 0, zIndex: 200,
        // No dimming or blur — the modal sits over the app undimmed, so the
        // conversation you were reading stays legible behind it. The layer is
        // still here, just transparent: it is what catches a click-outside,
        // and it is what centres the card.
        background: "transparent",
        display: "flex", alignItems: "center", justifyContent: "center",
        padding: 24
      }}>
      <style>{`
        @keyframes snmPop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }
        @keyframes snmSheen { from { background-position: 120% 0; } to { background-position: -120% 0; } }
        .snm-sk i { display: block; border-radius: 6px;
          background: linear-gradient(90deg,#F2F4F7,#E6E9EF,#F2F4F7); background-size: 220% 100%;
          animation: snmSheen 1.1s linear infinite; }
        .snm-key:hover { background: ${C.canvas}; border-color: ${C.line}; }
        .snm-line-opt:hover { background: ${C.canvas}; }
        .snm-icon-btn:hover { background: ${C.canvas}; color: ${C.ink2}; }
        /* Hover tints a row but does not move the cursor — the ↵ hint stays
           where the keyboard left it, so mousing over the list never changes
           what Enter would do. */
        .snm-person[aria-selected="false"]:hover { background: ${C.canvas}; }
        @media (prefers-reduced-motion: reduce) {
          .snm-sk i { animation: none; }
          .snm-modal { animation: none !important; }
        }
      `}</style>

      <div
        className="snm-modal"
        role="dialog"
        aria-modal="true"
        aria-labelledby="snm-title"
        onMouseDown={(e) => e.stopPropagation()}
        style={{
          position: "relative", width: 440, boxSizing: "border-box",
          background: "#FFFFFF", borderRadius: 16,
          // With nothing dimmed behind it the card has to draw its own edge: a
          // real border rather than the 4% ring that was only ever legible
          // against a darkened app. The shadow still does the lifting.
          border: `1px solid ${C.line}`,
          boxShadow: "0 24px 64px -12px rgba(16,24,40,0.30)",
          fontFamily: "Inter, sans-serif",
          overflow: linePop || settings ? "visible" : "hidden",
          animation: "snmPop .22s cubic-bezier(.2,.9,.3,1)"
        }}>

        {/* Header — title, and the audio settings the call will use */}
        <div style={{ display: "flex", alignItems: "flex-start", padding: "20px 20px 0" }} data-snm-audio>
          <h3 id="snm-title" style={{ margin: 0, fontSize: 18, fontWeight: 600, letterSpacing: "-0.02em", color: C.ink }}>
            New conversation
          </h3>
          <button
            className="snm-icon-btn"
            onClick={() => setSettings((s) => !s)}
            title="Audio and line settings"
            style={{
              marginLeft: "auto", width: 30, height: 30, borderRadius: 8, border: "none",
              background: settings ? C.soft : "transparent", color: settings ? C.ink2 : C.faint,
              display: "grid", placeItems: "center", cursor: "pointer", padding: 0
            }}>
            <I.settings size={16} stroke="currentColor" />
          </button>
          {settings &&
          <div style={{
            position: "absolute", top: 52, right: 14, width: 306, zIndex: 7,
            background: "#FFFFFF", border: `1px solid ${C.line}`, borderRadius: 12,
            boxShadow: "0 12px 32px -8px rgba(16,24,40,0.22), 0 0 0 1px rgba(16,24,40,0.06)",
            padding: "15px 15px 6px"
          }}>
              {[["mic", "Microphone"], ["spk", "Speaker"], ["ring", "Ringtone"]].map(([k, label]) =>
            <div key={k} style={{ marginBottom: 14 }}>
                  <label style={{ display: "block", fontSize: 12.5, fontWeight: 600, color: C.ink2, marginBottom: 6 }}>
                    {label}
                  </label>
                  <div style={{ position: "relative" }}>
                    <select
                  value={audio[k]}
                  onChange={(e) => setAudio((a) => ({ ...a, [k]: +e.target.value }))}
                  style={{
                    width: "100%", appearance: "none", WebkitAppearance: "none",
                    fontFamily: "inherit", fontSize: 13, color: C.ink, background: "#FFFFFF",
                    border: `1px solid ${C.line}`, borderRadius: 9, padding: "9px 34px 9px 11px",
                    outline: "none", textOverflow: "ellipsis", whiteSpace: "nowrap", overflow: "hidden",
                    cursor: "pointer"
                  }}>
                      {DEVICES[k].map((d, j) => <option key={j} value={j}>{d}</option>)}
                    </select>
                    <span style={{
                  position: "absolute", right: 10, top: "50%", transform: "translateY(-50%)",
                  color: C.muted, pointerEvents: "none", display: "flex"
                }}>
                      <I.chevDown size={14} stroke="currentColor" />
                    </span>
                  </div>
                </div>
            )}
            </div>
          }
        </div>

        {/* From line — a link, not a field. Right by default, changeable in two clicks. */}
        <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 5, padding: "15px 20px 0" }}>
          <span style={{ fontSize: 12, fontWeight: 500, color: C.muted }}>Start conversation from:</span>
          <span style={{ position: "relative" }} data-snm-line>
            <button
              onClick={() => setLinePop((o) => !o)}
              style={{
                display: "inline-flex", alignItems: "center", gap: 4, border: "none",
                background: "transparent", padding: 0, fontFamily: "inherit",
                fontSize: 12, fontWeight: 500, color: C.brand, cursor: "pointer",
                borderBottom: `1px solid ${linePop ? C.brandLine : "transparent"}`
              }}>
              {line ? `${line.name} · ${line.phone}` : "Select a line"}
              <I.chevDown size={13} stroke="currentColor" style={{ opacity: 0.75 }} />
            </button>
            {linePop &&
            <span style={{
              position: "absolute", zIndex: 5, top: "calc(100% + 8px)", left: -8, width: 292,
              background: "#FFFFFF", borderRadius: 12, padding: 6,
              border: `1px solid ${C.line}`,
              boxShadow: "0 12px 32px -8px rgba(16,24,40,0.22), 0 0 0 1px rgba(16,24,40,0.06)",
              maxHeight: 264, overflowY: "auto", display: "block"
            }}>
                {lines.map((l, i) =>
              <button key={l.id} className="snm-line-opt"
              onClick={() => { setLineIdx(i); setLinePop(false); }}
              style={{
                width: "100%", display: "flex", alignItems: "center", gap: 10,
                background: "transparent", border: "none", padding: "9px 10px",
                borderRadius: 8, textAlign: "left", cursor: "pointer", fontFamily: "inherit"
              }}>
                    <span style={{ fontSize: 15, lineHeight: 1 }}>{l.flag}</span>
                    <span style={{ minWidth: 0 }}>
                      <span style={{
                    display: "block", fontSize: 13, fontWeight: 600, color: C.ink,
                    whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis"
                  }}>{l.name}</span>
                      <span style={{ display: "block", fontSize: 12, color: C.muted }}>{l.phone}</span>
                    </span>
                    <span style={{ marginLeft: "auto", display: "flex", color: C.brand, visibility: i === lineIdx ? "visible" : "hidden" }}>
                      <I.check size={16} stroke="currentColor" />
                    </span>
                  </button>
              )}
              </span>
            }
          </span>
        </div>

        {/* The one field — a name, a number, or the recipient once picked */}
        <div style={{ display: "flex", alignItems: "center", gap: 9, padding: "20px 20px 24px" }}>
          {sel ?
          <React.Fragment>
              <span style={{
              display: "flex", alignItems: "center", gap: 8, background: C.brandSoft,
              border: `1px solid ${C.brandLine}`, borderRadius: 8, padding: "4px 8px 4px 4px",
              minWidth: 0
            }}>
                <Avatar tone={sel.raw ? "raw" : ""} size={22}>
                  {sel.raw ? "#" : sel.avatar || initials(sel.name)}
                </Avatar>
                <b style={{ fontSize: 13, fontWeight: 600, color: C.ink, whiteSpace: "nowrap" }}>{sel.name}</b>
                {!sel.raw && <small style={{ fontSize: 12, color: C.muted, whiteSpace: "nowrap" }}>{sel.sub}</small>}
              </span>
              <span style={{ flex: 1 }} />
              <button
              onClick={() => { setSel(null); setQ(""); setCur(0); }}
              title="Change recipient"
              style={toolBtn(false)}>
                <I.x size={16} stroke="currentColor" />
              </button>
            </React.Fragment> :

          <React.Fragment>
              <input
              ref={inputRef}
              value={q}
              onChange={(e) => setQuery(e.target.value)}
              inputMode={pad ? "tel" : "text"}
              placeholder="Enter a name or phone number…"
              style={{
                flex: 1, minWidth: 0, border: "none", outline: "none", background: "transparent",
                fontFamily: "inherit", fontSize: 16.5, lineHeight: 1.4, color: C.ink, padding: 0
              }} />
              {!!q.length &&
            <button
              className="snm-icon-btn"
              onClick={() => { setQuery(""); if (inputRef.current) inputRef.current.focus(); }}
              title="Clear"
              style={{
                width: 26, height: 26, flex: "0 0 26px", borderRadius: "50%", border: "none",
                background: "transparent", color: C.faint, display: "grid", placeItems: "center",
                cursor: "pointer", padding: 0
              }}>
                  <I.x size={14} stroke="currentColor" />
                </button>
            }
              <button
              onClick={() => {
                const next = !pad;
                setPad(next); setCur(0);
                // Leaving the keypad re-runs the search on whatever is typed;
                // entering it drops any search in flight.
                setLoading(!next && q.trim().length >= MIN_Q);
                if (inputRef.current) inputRef.current.focus();
              }}
              title={pad ? "Back to search" : "Keypad"}
              aria-pressed={pad}
              style={toolBtn(pad)}>
                <I.dialer size={16} stroke="currentColor" />
              </button>
            </React.Fragment>
          }
        </div>

        {/* Body — hint, skeleton, results, empty, or the keypad */}
        {sel ? null :
        pad ?
        <React.Fragment>
            {sep}
            <div style={{ padding: "18px 26px 24px" }}>
              <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "6px 10px" }}>
                {KEYS.map(([k, sub]) =>
              <button key={k} className="snm-key"
              onClick={() => {
                setQuery((q + k).slice(0, 18));
                flashKey(k);
                if (inputRef.current) inputRef.current.focus();
              }}
              style={{
                border: `1px solid ${flash === k ? C.brandLine : "transparent"}`,
                background: flash === k ? C.brandSoft : "transparent",
                color: flash === k ? C.brand : C.ink,
                borderRadius: 10, padding: "11px 0", lineHeight: 1.15, cursor: "pointer",
                fontFamily: "inherit",
                transform: flash === k ? "scale(.96)" : "none",
                transition: "background .12s ease, transform .12s ease, color .12s ease"
              }}>
                    <b style={{ fontSize: 21, fontWeight: 400, display: "block", color: "inherit" }}>{k}</b>
                    <small style={{
                  display: "block", fontSize: 9.5, letterSpacing: "0.12em",
                  color: C.faint, marginTop: 1, minHeight: 12
                }}>{sub}</small>
                  </button>
              )}
              </div>
            </div>
          </React.Fragment> :

        !query.length ?
        hint("Search your contacts by name, or type a full number to start a new thread.") :
        query.length < MIN_Q ?
        hint(`Keep typing — search starts at ${MIN_Q} characters.`) :
        loading ?
        <React.Fragment>
            {sep}
            <div className="snm-sk" style={{ maxHeight: 238, padding: "8px 12px 10px" }}>
              {[0, 1, 2].map((r) =>
            <div key={r} style={{ display: "flex", alignItems: "center", gap: 11, padding: "9px 10px" }}>
                  <i style={{ width: 30, height: 30, borderRadius: "50%", flex: "0 0 30px" }} />
                  <span>
                    <i style={{ height: 9, width: 138, marginBottom: 6 }} />
                    <i style={{ height: 8, width: 98 }} />
                  </span>
                </div>
            )}
            </div>
          </React.Fragment> :

        !items.length ?
        <React.Fragment>
            {sep}
            <div style={{ padding: "22px 14px 26px", textAlign: "center", color: C.muted, fontSize: 13, lineHeight: 1.55 }}>
              No contact matches “{query}”.<br />Enter a full phone number to reach someone new.
            </div>
          </React.Fragment> :

        <React.Fragment>
            {sep}
            <div style={{ maxHeight: 238, overflowY: "auto", padding: "8px 12px 10px" }}>
              {items.map((p, i) => <PersonRow key={`${p.name}-${i}`} p={p} i={i} />)}
            </div>
          </React.Fragment>
        }

        {/* Footer — only once there is someone to reach */}
        {recipient &&
        <div style={{
          display: "flex", alignItems: "center", gap: 10,
          padding: "11px 14px 12px", borderTop: `1px solid ${C.line}`,
          background: C.canvas, borderRadius: "0 0 16px 16px"
        }}>
            <span style={{ display: "flex", alignItems: "center", gap: 7, paddingLeft: 8, fontSize: 11.5, color: C.faint }}>
              <span style={kbd}>↵</span> message
              <span style={kbd}>⌘↵</span> call
            </span>
            <span style={{ marginLeft: "auto", display: "flex", gap: 9 }}>
              <button
              onClick={() => commit("call")}
              onMouseEnter={(e) => e.currentTarget.style.borderColor = C.line2}
              onMouseLeave={(e) => e.currentTarget.style.borderColor = C.line}
              style={{
                display: "flex", alignItems: "center", gap: 8, borderRadius: 9,
                padding: "9px 15px", fontSize: 13, fontWeight: 600, fontFamily: "inherit",
                border: `1px solid ${C.line}`, background: "#FFFFFF", color: C.ink, cursor: "pointer",
                transition: "border-color .12s ease"
              }}>
                <I.phone size={15} stroke="currentColor" /> Call
              </button>
              <button
              onClick={() => commit("message")}
              onMouseEnter={(e) => {e.currentTarget.style.background = C.brandHover;e.currentTarget.style.borderColor = C.brandHover;}}
              onMouseLeave={(e) => {e.currentTarget.style.background = C.brand;e.currentTarget.style.borderColor = C.brand;}}
              style={{
                display: "flex", alignItems: "center", gap: 8, borderRadius: 9,
                padding: "9px 15px", fontSize: 13, fontWeight: 600, fontFamily: "inherit",
                border: `1px solid ${C.brand}`, background: C.brand, color: "#FFFFFF", cursor: "pointer",
                transition: "background .12s ease, border-color .12s ease"
              }}>
                <I.sms size={15} stroke="currentColor" /> Message
              </button>
            </span>
          </div>
        }
      </div>
    </div>);

};

window.StartNewModal = StartNewModal;
