# Modern tmux config with sensible defaults

# --- General ---
set -g default-terminal "tmux-256color"
set -g history-limit 1000000
set -g mouse on
set -g focus-events on

# Faster escape time (for vim/TUI apps)
set -sg escape-time 0
set -sg repeat-time 300

# --- Terminal features for modern TUI apps ---
# True color support
set -sa terminal-features ',xterm-ghostty:RGB'
set -sa terminal-features ',xterm-256color:RGB'
set -sa terminal-overrides ',xterm-256color:Tc'

# Extended keys (Ctrl+Shift, etc. for Claude Code, neovim, etc.)
set -g extended-keys on
set -sa terminal-features ',xterm-ghostty:extkeys'
set -sa terminal-features ',xterm-256color:extkeys'

# Clipboard via OSC 52 (works over SSH)
set -g set-clipboard on
set -g allow-passthrough on
set -sa terminal-features ',xterm-ghostty:clipboard'
set -sa terminal-features ',xterm-256color:clipboard'

# Cursor style passthrough (for neovim cursor changes)
set -sa terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'

# Undercurl support (for neovim diagnostics)
set -sa terminal-overrides ',*:Smulx=\E[4::%p1%dm'
set -sa terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'

# Start windows and panes at 1
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on

# --- Prefix ---
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# --- Keybindings ---
# Reload config
bind r source-file ~/.tmux.conf \; display "Config reloaded"

# Split panes (intuitive keys)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
unbind '"'
unbind %

# Vim-style pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Window navigation
bind -r n next-window
bind -r p previous-window
bind Tab last-window

# Copy mode (vi style)
setw -g mode-keys vi
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send -X copy-selection-and-cancel
bind -T copy-mode-vi Escape send -X cancel

# --- Status bar ---
set -g status-position top
set -g status-interval 5
set -g status-style 'bg=#1a1a1a fg=#808080'

# Left: session name
set -g status-left-length 30
set -g status-left '#[fg=#c0c0c0,bold] #S #[fg=#404040]|'

# Right: minimal info
set -g status-right-length 50
set -g status-right '#[fg=#606060]%H:%M #[fg=#404040]| #[fg=#808080]%d %b'

# Window status
setw -g window-status-format ' #I:#W '
setw -g window-status-current-format '#[fg=#c0c0c0,bold] #I:#W '
setw -g window-status-separator ''

# Pane borders
set -g pane-border-style 'fg=#303030'
set -g pane-active-border-style 'fg=#606060'

# Messages
set -g message-style 'bg=#1a1a1a fg=#c0c0c0'
