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

{
  programs.hyprland = {
    enable = true;
    package = inputs.hyprland.packages.${pkgs.system}.hyprland;
    portalPackage = inputs.hyprland.packages.${pkgs.system}.xdg-desktop-portal-hyprland;
  };

  services.displayManager.sddm = {
    enable = true;
    wayland.enable = true;
    enableHidpi = true;
  };

  # Environment variables for Wayland
  environment.sessionVariables = {
    NIXOS_OZONE_WL = "1";

    # QT Variables
    QT_QPA_PLATFORM = "wayland";
    QT_WAYLAND_DISABLE_WINDOWDECORATION = "1";
    QT_AUTO_SCREEN_SCALE_FACTOR = "1";

    # Toolkit Backends
    GDK_BACKEND = "wayland,x11,*";
    SDL_VIDEODRIVER = "wayland";
    CLUTTER_BACKEND = "wayland";

    # XDG Specifications
    XDG_CURRENT_DESKTOP = "Hyprland";
    XDG_SESSION_TYPE = "wayland";
    XDG_SESSION_DESKTOP = "Hyprland";
  };

  environment.systemPackages = with pkgs; [
    # Core
    waybar              # Status bar
    rofi-wayland        # App launcher
    swaynotificationcenter # Notifications
    libnotify           # Notification library

    # Theming & Wallpaper
    swww                # Wallpaper daemon
    hyprcursor          # Cursor theme manager

    # Utilities
    wl-clipboard        # Clipboard manager
    cliphist            # Clipboard history
    grim                # Screenshot tool
    slurp               # Region selector
    swappy              # Screenshot editor
    hyprpicker          # Color picker

    # System Management
    hypridle            # Idle daemon
    hyprlock            # Screen locker
    wlogout             # Logout menu

    # Audio
    pamixer
    playerctl

    # File Management
    # (Dolphin or Nautilus usually handled by user preference, keeping system clean)

    # Polkit Agent
    polkit_gnome
  ];

  # Security / Polkit
  security.polkit.enable = true;

  systemd.user.services.polkit-gnome-authentication-agent-1 = {
    description = "polkit-gnome-authentication-agent-1";
    wantedBy = [ "graphical-session.target" ];
    wants = [ "graphical-session.target" ];
    after = [ "graphical-session.target" ];
    serviceConfig = {
      Type = "simple";
      ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
      Restart = "on-failure";
      RestartSec = 1;
      TimeoutStopSec = 10;
    };
  };

  # Portals
  xdg.portal = {
    enable = true;
    extraPortals = [
      pkgs.xdg-desktop-portal-gtk
    ];
  };
}
