set -g mouse on
set -g history-limit 100000
set -g set-clipboard on

# Persistence-first tmux: keep it out of the way during SSH/TUI use.
unbind C-b
set -g prefix C-\\
bind C-\\ send-prefix
set -g status off
set -sg escape-time 10

# Better terminal support over SSH.
set -g default-terminal "tmux-256color"
set -as terminal-overrides ',xterm-256color:Tc'
set -as terminal-overrides ',tmux-256color:Tc'
set -g extended-keys on
set -g extended-keys-format csi-u
set -as terminal-features ",xterm-256color:clipboard"
set -as terminal-features ",screen-256color:clipboard"
set -as terminal-features ",tmux-256color:clipboard"

# Vi-style copy/scroll mode.
setw -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
bind-key PageUp copy-mode -u
bind -n WheelUpPane if-shell -F '#{pane_in_mode}' 'send-keys -X scroll-up' 'copy-mode -e'
bind -n WheelDownPane if-shell -F '#{pane_in_mode}' 'send-keys -X scroll-down' 'send-keys -X cancel'

# Remove dangerous/default interactive UI bindings.
unbind '"'
unbind %
unbind c
unbind n
unbind p
unbind ,
unbind w
unbind d

# Keep only explicit escape hatches.
bind D detach-client
bind r source-file ~/.tmux.conf \; display-message "tmux.conf reloaded"
