{ config, pkgs, inputs, ... }:

{
  home.username = "lusia";
  home.homeDirectory = "/home/lusia";
  home.stateVersion = "24.11";

  nixpkgs.config.allowUnfree = true;

  home.packages = with pkgs; [
    # Window manager & desktop environment
    inputs.niri.packages.${pkgs.stdenv.hostPlatform.system}.niri
    swayidle
    swww
    kanshi

    # System utilities & monitoring
    btop
    htop
    fastfetch
    dua
    nh
    dconf
    gparted
    mission-center
    gnome-software

    # CLI tools & utilities
    ripgrep
    fd
    jq
    entr
    mdcat
    sshpass
    exiftool

    # File managers & compression tools
    yazi
    nautilus
    file-roller
    p7zip
    unzip
    zip
    unrar

    # Media viewers & players
    loupe
    evince
    vlc
    mpv
    zathura

    # SDR
    gqrx
    gnuradio
    gnuradioPackages.lora_sdr

    # Media creation & editing
    gimp
    blender
    ffmpeg
    yt-dlp
    waifu2x-converter-cpp
    libheif
    upscayl
    inkscape

    # Office & productivity
    libreoffice-fresh
    gnome-text-editor
    gnome-calculator
    obsidian
    simple-scan
    system-config-printer

    # Development tools
    neovim
    vscode.fhs
    lazygit
    cargo-cross
    cargo-generate
    probe-rs-tools
    elf2uf2-rs
    dbeaver-bin
    gnome-boxes
    cutecom
    inputs.binaryninja.packages.${pkgs.stdenv.hostPlatform.system}.binary-ninja-free-wayland

    # AI development tools
    inputs.claude-code-nix.packages.${pkgs.stdenv.hostPlatform.system}.default
    inputs.codex-cli-nix.packages.${pkgs.stdenv.hostPlatform.system}.default
    gemini-cli

    # Internet & networking
    firefox-bin
    filezilla
    qbittorrent
    tor-browser
    nmap
    gnome-network-displays

    # Privacy & security
    gnupg
    pinentry-qt
    kdePackages.kleopatra
    monero-gui

    # Python & AI
    python314
    openai-whisper

    # Document processing
    tectonic
    mermaid-cli

    # Theming
    pywal
    pywalfox-native
    morewaita-icon-theme

    # Astronomy
    stellarium
    kstars

    # Wrap PrismLauncher to fix Minecraft GLFW Wayland issues
    (pkgs.symlinkJoin {
      name = "prismlauncher";
      paths = [ pkgs.prismlauncher ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = ''
        wrapProgram $out/bin/prismlauncher \
          --set SDL_VIDEODRIVER "x11"
      '';
    })

    # Wrap Krita to work with XWayland (Krita doesn't support native Wayland)
    (pkgs.symlinkJoin {
      name = "krita";
      paths = [ pkgs.krita ];
      buildInputs = [ pkgs.makeWrapper ];
      postBuild = ''
        wrapProgram $out/bin/krita \
          --set DISPLAY ":0" \
          --set QT_AUTO_SCREEN_SCALE_FACTOR "0" \
          --set QT_SCALE_FACTOR "2" \
          --set QT_FONT_DPI "96"
      '';
    })
  ];

  # Set dark mode and Nautilus preferences
  dconf = {
    enable = true;
    settings = {
      "org/gnome/desktop/interface" = {
        color-scheme = "prefer-dark";
      };
      "org/gnome/nautilus/preferences" = {
        show-image-thumbnails = "always";
      };
    };
  };
  # Set morewaita as the default icon theme
  gtk = {
    enable = true;

    iconTheme = {
      name = "MoreWaita";
      package = pkgs.morewaita-icon-theme;
    };

    # Stylix manages theme, commenting out manual config
    # theme = {
    #   name = "Adwaita-dark";
    #   package = pkgs.gnome-themes-extra;
    # };

    cursorTheme = {
      name = "Adwaita";
      package = pkgs.adwaita-icon-theme;
    };

    # Force dark mode preference for GTK3
    gtk3.extraConfig = {
      gtk-application-prefer-dark-theme = 1;
    };

    # Force dark mode preference for GTK4
    gtk4.extraConfig = {
      gtk-application-prefer-dark-theme = 1;
    };
  };

  home.pointerCursor = {
    name = "Adwaita";
    package = pkgs.adwaita-icon-theme;
    size = 24;
    gtk.enable = true;
    x11 = {
      enable = true;
      defaultCursor = "Adwaita";
    };
  };

  qt = {
    enable = true;
    platformTheme.name = "adwaita";
    style = {
      name = "adwaita-dark";
    };
  };

  # Enable and configure git
  programs.git = {
    enable = true;
    settings = {
      user.name = "Lukrecja Pleskaczyńska";
      user.email = "lukrecjaaa@proton.me";
      credential.helper = "store";
      http."https://git.bgs.local:3000/" = {
        sslCAInfo = "/home/lusia/VSTech-vpn/bgs-git-ca.crt";
      };
    };
  };

  # Configure GPG agent with pinentry
  services.gpg-agent = {
    enable = true;
    pinentry.package = pkgs.pinentry-qt;
    enableSshSupport = true;
  };

  # OBS with plugins
  programs.obs-studio = {
    enable = true;

    plugins = with pkgs.obs-studio-plugins; [
      wlrobs
      obs-backgroundremoval
      obs-pipewire-audio-capture
      obs-vaapi
    ];
  };

  programs.home-manager.enable = true;

  # Stylix theming
  stylix = {
    enable = true;

    # Wallpaper required by Stylix (even though we use swww to actually display it)
    image = ./wallpaper;

    # Use pywal's color scheme instead of extracting from image
    # sync-colors.sh will generate colors.yaml here
    base16Scheme = ./colors.yaml;

    # Use dark mode
    polarity = "dark";

    # Disable Qt theming (it's janky and doesn't apply everywhere)
    # targets.qt.enable = false;
  };
}
